if("undefined"==typeof CLUB||!CLUB)var CLUB={};
//命名空间 CLUB.xxx
CLUB.namespace = function(ns) {   
    if (!ns || !ns.length) {   
        return null;   
    }
    var levels = ns.split(".");   
    var nsobj = CLUB;   
    for (var i=(levels[0] == "CLUB") ? 1 : 0; i<levels.length; ++i) {   
        nsobj[levels[i]] = nsobj[levels[i]] || {};   
        nsobj = nsobj[levels[i]];   
    }   
    return nsobj;   
};

//全部变量，需要外部调用初始化
CLUB.namespace("global");
CLUB.global={
    isLogin:false,
    isClubAdmin:false,
    isPresident:false,
    isMember:false,
    ROOT:"",
    BBSROOT:"",
    UCROOT:"",
    BIPROOT:"",
    clubUrl:"",
    clubName:"",
    oClubId:0,
    userId:0,
    nickName:"",
    sessionName:"common_session_id",
    dynaType:{
        topic:1,
        comment:2,
        picture:3,
        question:4,
        notice:5,
        activity:6,
        join:7,
        create:8
    },
    _loadingFlagMap:{},
    loading:function(key,val){
        if("undefined"==typeof val){
            return this._loadingFlagMap[key];
        }else{
            this._loadingFlagMap[key]=(val===true);
            return true;
        }
    },
    _pageNoMap:{},
    addPageNo:function(key){
        if("undefined"==typeof this._pageNoMap[key]){
            this._pageNoMap[key]=0;
        }
        return ++this._pageNoMap[key];
    },
    init:function(cfg){
        CLUB.global = $.extend({},CLUB.global,cfg);
    },
    _dataMap:{},
    isOverData:function(val){
        if("undefined"==typeof val){
            return this._dataMap["isOver"];
        }else{
            this._dataMap["isOver"]=(val===true);
        }
    }
};

// 弹窗模块
CLUB.namespace("alert");
CLUB.alert={
    _maskBg:$("#mark-bg"),
    init:function(){
        /*初始化遮罩层的高度*/
        var maskBg=$("#mark-bg");
        maskBg.height($(window).height());
        $(window).resize(function(){
            maskBg.height($(window).height());
        });
        this._maskBg=maskBg;
    },
    _show:function(cfg){
        cfg = $.extend({}, {
            name:"",//主要是区别公共弹窗还是其它弹窗。值目前可选"alert"、"login"、"share"、"album"、"ubsave"、"bind-phone";
            title:"",//标题
            tip:"",//提示文字
            btnHtml:"",//传入方法中的按钮html片断。考虑到有确定操作后会有其实方法的绑定，以及按钮数量不一定是两个，故整块抽出来，由使用者自定义;
            icon:"warning",//提示图标类型：warning为警示图标(默认)，success为成功图标，none表示不需要图标;
            closeMask:true//是否关闭背景
        }, cfg);
        var pop=$("#pop-"+cfg.name);
        var popClose=pop.find(".close")
        this._maskBg.show(); 
        if(cfg.name==="alert"){       
            var iconHtml="",spanCn="";
            if(cfg.icon==="warning"){
                iconHtml="<em></em>";
            }else if(cfg.icon==="success"){
                iconHtml="<em class=\"s\"></em>";
            }else if(cfg.icon==="none"){
                iconHtml="";
                spanCn="txtblock";
            }
            var html=iconHtml+'<span class="'+spanCn+'">'+cfg.tip+'</span>';
            $("#alert-bd").html(html);
            $("#pop-btns").html(cfg.btnHtml);
            pop.find(".pop-th .tit").html(cfg.title);
        }
        pop.show();
        popClose.click(function(){
            pop.hide();
            if(cfg.closeMask){
                CLUB.alert._maskBg.hide();
            }         
        });
    },
    _hide:function(cfg){
        cfg = $.extend({}, {
            name:"",
            closeMask:false
        }, cfg);
        var pop=$("#pop-"+cfg.name);
        pop.hide();
        if(cfg.closeMask){
            CLUB.alert._maskBg.hide();
        }
    },
    info:function(txt,callback){
        if(txt){
            $("#Jsuccess-txt").html(txt);
        }else{
            $("#Jsuccess-txt").html("保存成功");
        }
        $('#mark-bg').show();
        $("#Jsuccess").css({
            marginLeft:-$("#Jsuccess").width()/2
        }).show();
        setTimeout(function(){
            $('#Jsuccess').hide();
            $('#mark-bg').hide();
            if(callback){
                callback();
            }
        },1500)
    },
    confirm:function(txt,funStr){
        var btnHtml = '<a class="cancel" href="javascript:void(0)" onclick="CLUB.alert.hide(true);">取消</a><a class="sure" href="javascript:$fun">确定</a>';
        btnHtml = btnHtml.replace("$fun",funStr);
        this._show({
            name:"alert",
            tip:txt,
            icon:"none",
            btnHtml:btnHtml
        });
    },
    successCall:function(txt,funStr){
        var btnHtml = '<a class="sure" href="javascript:$fun">确定</a>';
        btnHtml = btnHtml.replace("$fun",funStr);
        this._show({
            name:"alert",
            tip:txt,
            icon:"success",
            btnHtml:btnHtml
        });
    },
    success:function(txt,closeMask){
        if(!txt){
            txt = ("保存成功");
        }
        var btnTxt = "确定";
        if(closeMask!==false){
            closeMask=true;
        }
        var btnHtml = '<a class="sure" href="javascript:CLUB.alert.hide('+closeMask+')">'+btnTxt+'</a>';
        this._show({
            name:"alert",
            tip:txt,
            icon:"success",
            closeMask:closeMask,
            btnHtml:btnHtml
        });    
    },
    error:function(txt,closeMask,btnTxt){
        if(!txt){
            txt = ("保存失败");
        }
        if(!btnTxt){
            btnTxt = "确定";
        }
        if(closeMask!==false){
            closeMask=true;
        }
        var btnHtml = '<a class="sure" href="javascript:CLUB.alert.hide('+closeMask+')">'+btnTxt+'</a>';
        this._show({
            name:"alert",
            tip:txt,
            icon:"warning",
            closeMask:closeMask,
            btnHtml:btnHtml
        });
    },
    hide:function(closeMask){
        this._hide({
            name:"alert",
            closeMask:closeMask
        });
    }
};
CLUB.alert.init();

//异步请求结果解析模块
CLUB.namespace("json");
CLUB.json={
    isSuccess:function(a){
        return 0==a.code;
    },
    isError:function(a){
        return 1002==a.code;
    },
    isNoPermission:function(a){
        return 1001==a.code;
    },
    isNoLogin:function(a){
        return 1003==a.code;
    },
    getMsg:function(a){
        return a.message;
    }
};

// 异步请求模块
CLUB.namespace("ajax");
CLUB.ajax={
    _ajax:function(type,url,data,success,fail){
        $.ajax({
            url:url,
            data:data,
            dataType:"json",
            type:type,
            success:function(rs){
                if(CLUB.json.isNoLogin(rs)){
                    CLUB.login.showDialog();
                }else if(CLUB.json.isSuccess(rs)){
                    if(success)
                        success(rs);
                }else{
                    if(fail)
                        fail(rs);
                }
            },
            error:function(xmlHttpRequest, textStatus, errorThrown){
                var message = "提交失败，请检查后重新提交或联系客服人员，非常抱歉...";
                if(xmlHttpRequest.status==503){
                    var json = eval("("+xmlHttpRequest.responseText+")");
                    message = (json.message == ""?message:json.message);
                }
                CLUB.alert.error(message);
            }
        });
    },
    post:function(url,data,success,fail){
        this._ajax("post", url,data,success,fail);
    },
    get:function(url,data,success,fail){
        this._ajax("get", url,data,success,fail);
    },
    jsonp:function(url,data,callback){
        $.getJSON(url,data,callback);
    }
};

// 公共服务模块
CLUB.namespace("common");
CLUB.common={
    reload:function(){
        window.location.reload(true);
    },
    faceUrl:function(uid){
        uid+="";
        var picPath = "http://i6.3conline.com/images/upload/upc/face/";
        for(var i=0,s=uid.length;i<s;i++){
            var k = (i+2)<=s?(i+2):(i+1);
            picPath += uid.substring(i, k) +"/";
            i++;
        }
        return picPath+uid;
    },
    //获取头像地址,指定图片大小 20,50,70,100,120,150
    faceSizeUrl:function(uid,sz){
        var facesrc = CLUB.common.faceUrl(uid);
        if(facesrc.length==0)
            return "";
        if(typeof(sz)=="undefined")
            sz = 50;
        return facesrc + "_" + sz +"x"+sz;
    },
    checkAdmin : function(){
        if(!CLUB.global.isLogin){
            CLUB.login.showDialog();
            return false;
        }
        if(CLUB.global.isClubAdmin){
            return true;
        }else{
            CLUB.alert.error("您不是本车友会的管理员");
            return false;
        }
    },
    copyText:function(clipId,btnId,text,popId,callback){
        if(window['clip'+clipId]){
            window['clip'+clipId].show();
            return;
        }
        ZeroClipboard.setMoviePath("/js/ZeroClipboard.swf");
        var clip = new ZeroClipboard.Client();
        clip.setHandCursor(true);          
        clip.addEventListener('mouseOver', function (client) {
            clip.setText(text);
        });  
        clip.addEventListener('complete', function (client, text) {
            callback();
        });
        clip.glue(btnId,popId);
        window['clip'+btnId]=clip;
    },
    addJsByLink:function(url,attrs){
        var ele=document.createElement("script");
        ele.setAttribute("type","text/javascript");
        ele.setAttribute("src",url);
        if(attrs)for(var e=0;e<attrs;e++)ele.setAttribute(attrs[e].key,attrs[e].value);
        var body=document.getElementsByTagName("body");
        body.length?body[0].appendChild(ele):document.documentElement.appendChild(ele)
    },
    initSlide:function($target,$control,$img,callback){
        if($target.length==1){
            if(callback)
                callback($target[0]);
            $img.attr('src',$img.attr('#src'));
        }
        if($target.length>=2){
            var m=0;
            new Slide({
                target: $target,
                control: $control,
                effect: 'slide',
                autoPlay: true,
                stay: 5000,
                onchange: function(){
                    var num = $target.length;
                    if(m<num){//图片只加载一次就好了
                        var nli = this.target[this.curPage].getElementsByTagName("img")[0];
                        if(nli.getAttribute("#src")) {
                            nli.src = nli.getAttribute("#src");
                            nli.removeAttribute("#src");
                        }
                    }
                    m++;
                    if(callback)
                        callback(this.target[this.curPage]);
                }
            });                 
        }
    },
    initGoToTop:function(){
        if(window.screen.width <= 1024){
            $$("floatBtns").style.display="none";
        }
        else{
            $("#floatBtns").show()
        }
        window.onscroll=window.onresize=function(){
            var top = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;              
            var goTop =$('#JgoTop');              
            if(top > 600){
                goTop.css("display","block");
            }else{
                goTop.css("display","none");
            }
        }
        $("#floatBtns .btn").hover(
            function(){
                $(this).addClass("hover");   
            },
            function(){
                $(this).removeClass("hover");   
            });
    }
};

//表情模块
CLUB.namespace("emotion");
CLUB.emotion={
    _smilies_array:[],
    init:function(){
        this._smilies_array[0] = [];
        this._smilies_array[0][1] = 
        [['em2001','[抠鼻]','em1017.gif','32','32','50'],
        ['em2002','[鼓掌]','em1017.gif','32','32','50'],
        ['em2003','[可爱]','em1017.gif','32','32','50'],
        ['em2004','[偷笑]','em1017.gif','32','32','50'],
        ['em2005','[晕]','em1017.gif','32','32','50'],
        ['em2006','[调皮]','em1017.gif','32','32','50'],
        ['em2007','[微笑]','em1017.gif','32','32','50'],
        ['em2008','[流泪]','em1017.gif','32','32','50'],
        ['em2009','[大哭]','em1017.gif','32','32','50'],
        ['em2010','[憨笑]','em1017.gif','32','32','50'],
        ['em2011','[闭嘴]','em1017.gif','32','32','50'],
        ['em2012','[鄙视]','em1017.gif','32','32','50'],
        ['em2013','[可怜]','em1017.gif','32','32','50'],
        ['em2014','[无语]','em1017.gif','32','32','50'],
        ['em2015','[发呆]','em1017.gif','32','32','50'],
        ['em2016','[吐]','em1017.gif','32','32','50'],
        ['em2017','[流汗]','em1017.gif','32','32','50'],
        ['em2018','[翻白眼]','em1017.gif','32','32','50'],
        ['em2019','[发怒]','em1017.gif','32','32','50'],
        ['em2020','[尴尬]','em1017.gif','32','32','50'],
        ['em2021','[亲亲]','em1017.gif','32','32','50'],
        ['em2022','[擦汗]','em1017.gif','32','32','50'],
        ['em2023','[快哭了]','em1017.gif','32','32','50'],
        ['em2024','[色色]','em1017.gif','32','32','50'],
        ['em2025','[阴险]','em1017.gif','32','32','50'],
        ['em2026','[得意]','em1017.gif','32','32','50'],
        ['em2027','[睡觉]','em1017.gif','32','32','50'],
        ['em2028','[叹气]','em1017.gif','32','32','50'],
        ['em2029','[嘘]','em1017.gif','32','32','50'],
        ['em2030','[撇嘴]','em1017.gif','32','32','50'],
        ['em2031','[傲慢]','em1017.gif','32','32','50'],
        ['em2032','[饿]','em1017.gif','32','32','50'],
        ['em2033','[困]','em1017.gif','32','32','50'],
        ['em2034','[委屈]','em1017.gif','32','32','50'],
        ['em2035','[骷髅]','em1017.gif','32','32','50'],
        ['em2036','[敲头]','em1017.gif','32','32','50'],
        ['em2037','[惊讶]','em1017.gif','32','32','50'],
        ['em2038','[咒骂]','em1017.gif','32','32','50'],
        ['em2039','[抓狂]','em1017.gif','32','32','50'],
        ['em2040','[奋斗]','em1017.gif','32','32','50'],
        ['em2041','[哼哼]','em1017.gif','32','32','50'],
        ['em2042','[惊恐]','em1017.gif','32','32','50'],
        ['em2043','[衰]','em1017.gif','32','32','50'],
        ['em2044','[疑问]','em1017.gif','32','32','50'],
        ['em2045','[拜拜]','em1017.gif','32','32','50'],
        ['em2046','[强]','em1017.gif','32','32','50'],
        ['em2047','[弱爆]','em1017.gif','32','32','50'],
        ['em2048','[OK]','em1017.gif','32','32','50'],
        ['em2049','[握手]','em1017.gif','32','32','50'],
        ['em2050','[胜利]','em1017.gif','32','32','50'],
        ['em2051','[大便]','em1017.gif','32','32','50'],
        ['em2052','[心碎]','em1017.gif','32','32','50'],
        ['em2053','[玫瑰]','em1017.gif','32','32','50'],
        ['em2054','[小刀]','em1017.gif','32','32','50'],
        ['em1001','[顶]','em1017.gif','32','32','50'],
        ['em1002','[微笑]','em1017.gif','32','32','50'],
        ['em1003','[晕]','em1017.gif','32','32','50'],
        ['em1004','[汗]','em1017.gif','32','32','50'],
        ['em1005','[抱抱]','em1017.gif','32','32','50'],
        ['em1006','[狂笑]','em1017.gif','32','32','50'],
        ['em1007','[害羞]','em1017.gif','32','32','50'],
        ['em1008','[大哭]','em1017.gif','32','32','50'],
        ['em1009','[吐]','em1017.gif','32','32','50'],
        ['em1010','[问]','em1017.gif','32','32','50'],
        ['em1011','[闭嘴]','em1017.gif','32','32','50'],
        ['em1012','[鄙视]','em1017.gif','32','32','50'],
        ['em1013','[胜利]','em1017.gif','32','32','50'],
        ['em1014','[无语]','em1017.gif','32','32','50'],
        ['em1015','[美女]','em1017.gif','32','32','50'],
        ['em1016','[鬼脸]','em1017.gif','32','32','50'],
        ['em1017','[白眼]','em1017.gif','32','32','50'],
        ['em1018','[吻]','em1017.gif','32','32','50'],
        ['em1019','[凶]','em1017.gif','32','32','50'],
        ['em1020','[路过]','em1017.gif','32','32','50'],
        ['em1021','[口水]','em1017.gif','32','32','50'],
        ['em1022','[电话]','em1017.gif','32','32','50'],
        ['em1023','[委屈]','em1017.gif','32','32','50'],
        ['em1024','[握手]','em1017.gif','32','32','50'],
        ['em1025','[已阅]','em1017.gif','32','32','50'],
        ['em1026','[再见]','em1017.gif','32','32','50'],
        ['em1027','[抓狂]','em1017.gif','32','32','50'],
        ['em1028','[鼓掌]','em1017.gif','32','32','50'],
        ['em1029','[无聊]','em1017.gif','32','32','50'],
        ['em1030','[害怕]','em1017.gif','32','32','50'],
        ['em1031','[嘘]','em1017.gif','32','32','50'],
        ['em1032','[下台]','em1017.gif','32','32','50'],
        ['em1033','[偷看]','em1017.gif','32','32','50'],
        ['em1034','[加油]','em1017.gif','32','32','50'],
        ['em1035','[可怜]','em1017.gif','32','32','50'],
        ['em1036','[受伤]','em1017.gif','32','32','50'],
        ['em1037','[吃惊]','em1017.gif','32','32','50'],
        ['em1038','[帅气]','em1017.gif','32','32','50'],
        ['em1039','[睡觉]','em1017.gif','32','32','50'],
        ['em1040','[发火]','em1017.gif','32','32','50'],
        ['em1041','[酷]','em1017.gif','32','32','50'],
        ['em1042','[思考]','em1017.gif','32','32','50'],
        ['em1043','[得意]','em1017.gif','32','32','50'],
        ['em1044','[聪明]','em1017.gif','32','32','50'],
        ['em1045','[贪钱]','em1017.gif','32','32','50'],
        ['em1046','[痛苦]','em1017.gif','32','32','50'],
        ['em1047','[敬礼]','em1017.gif','32','32','50'],
        ['em1048','[牛气冲天]','em1017.gif','32','32','50'],
        ['em1049','[抠鼻子]','em1017.gif','32','32','50'],
        ['em1050','[膜拜]','em1017.gif','32','32','50'],
        ['em1051','[潜水]','em1017.gif','32','32','50'],
        ['em1052','[挨打]','em1017.gif','32','32','50'],
        ['em1053','[骷髅]','em1017.gif','32','32','50'],
        ['em1054','[抱拳]','em1017.gif','32','32','50']];  
    },
    showInReply:function(e){
        $(e).parent().find(".replyData-face-pop").toggle();
    },
    showInPost:function(e){
        if($("#replyData-face-pop").length==0){//首次加载
            var showfaceDiv = $(template("template-dynaReplyFace",{
                tmpType:"postDyna",
                showFunction:"CLUB.emotion.showInPost(this);",
                selectFunction:"CLUB.emotion.selectInPost(this);"
            })).html();
            $("body").append($(showfaceDiv).attr("id","replyData-face-pop"));
        }
       
        $("#replyData-face-pop").toggle(0,function(){
            $(e).append($(this));
        });
    },
    showInDetail:function(e){
        if($("#replyData-face-pop").length==0){//首次加载
            var showfaceDiv = $(template("template-dynaReplyFace",{
                tmpType:"postDyna",
                showFunction:"CLUB.emotion.showInDetail(this);",
                selectFunction:"CLUB.emotion.selectInReply(this);"
            })).html();
            $("body").append($(showfaceDiv).attr("id","replyData-face-pop"));
        }
        $("#replyData-face-pop").toggle(0,function(){
            $(e).append($(this));
        });
    },
    selectInPost:function(e){
        var facestr = $(e).find("img").attr("title");
        var faceinput = $(e).parents(".publish-box-btns").prev().find("textarea");
        var txtarea = faceinput.val();
        if(txtarea == $(faceinput).attr("defaultValue")){txtarea = "";}
        faceinput.val(txtarea+facestr);
        var l= CLUB.emotion.transformToUBB(faceinput.val()).length;
        $("#publish-box-textarea-num").html(l+'/300');
        if(l>300){
            $("#publish-box-textarea-num").css("color","red");
        }else{
            $("#publish-box-textarea-num").css("color","#777");
        }
    },
    selectInReply:function(e){
        var facestr = $(e).find("img").attr("title");
        var $faceinput = $(e).parents(".replyData-tool").prev().find("input");
        $faceinput.val($faceinput.val()+facestr);
        CLUB.reply.initBtnStyle($faceinput);
    },
    transformToHTML:function(str){
        var me = this;
        for(var i=me._smilies_array[0][1].length-1; i>=0; i--) {
            var p = new RegExp("\\["+me._smilies_array[0][1][i][0]+"\\]", 'gm');
            str = str.replace(p, "<img width=22 height=22 src=\"http://www1.pcauto.com.cn/autobbs/2013/images/emot/"+me._smilies_array[0][1][i][0]+".gif\">");
        }
        return str;
    },
    transformToUBB:function(str){
        var me = this;
        for(var i=0,len=me._smilies_array[0][1].length; i<len; i++) {
            var p = new RegExp(me._smilies_array[0][1][i][1].replace('[', '\\[').replace(']', '\\]'), 'gm');
            str = str.replace(p, '['+me._smilies_array[0][1][i][0]+']');
        }
        return str;
    }
};
CLUB.emotion.init();

//动态模块
CLUB.namespace("dyna");
CLUB.dyna={
    initPraise:function(clickCall,unClickCall){
        //点赞动画
        $(".btn-zan").live('click',function(){
            var $btn = $(this);
            var isPraise = 0;
            if(!CLUB.global.isLogin){
                CLUB.login.showDialog();
                return ;
            }
            var elem_s=$btn.children("s");
            var s=elem_s.html();
            if($btn.attr("data-isClick")=="false"){
                isPraise = 1;
                elem_s.html(s*1+1);/*点赞数量+1*/ 
                $btn.addClass("btn-zan-active");       
                $btn.attr("data-isclick","true");
                var sp=$btn.position();
                var elem_i=$("#icon-zan");
                elem_i.attr("style","left:"+sp.left+"px;top:"+sp.top+"px");
                elem_i.animate({
                    marginTop: -30, 
                    opacity: 0
                },500);
                
                $(this).attr("data-isClick","true");
                if(clickCall){
                    clickCall();
                }
            }else{
                $btn.attr("data-isClick","false");
                $btn.removeClass("btn-zan-active");
                elem_s.html(s*1-1);
                if(unClickCall){
                    unClickCall();
                }
            }   
            CLUB.ajax.post(CLUB.global.ROOT+"/dyna/doPraise.do", {
                createDate:$btn.parents(".dontai").attr("data-createDate"),
                dynaInfoId:$btn.parents(".dontai").attr("data-dynaInfoId"),
                isPraise:isPraise
            });
        });
    },
    initFocus:function(){
        if(CLUB.global.isLogin){
            $(".dongtai-user-face").live('mouseenter',function(){
                if($(this).attr("data-userId")!=CLUB.global.userId){
                    $(this).addClass("hover");
                }else{
                    
                }
            }).live('mouseleave',function(){
                if($(this).attr("data-userId")!=CLUB.global.userId){
                    $(this).removeClass("hover");
                }else{
                    
                }
            });
        }
        $(".dongtai-user-face .follow[data-isFollow=true]").live("click",function(){
            if(!CLUB.global.isLogin){
                CLUB.login.showDialog();
                return ;
            }
            var $this = $(this);
            var fid=$this.parent(".dongtai-user-face").attr("data-userId");
            CLUB.ajax.post(CLUB.global.ROOT+"/intf/focus.jsp",{
                act:"delete",
                accountId:CLUB.global.userId,
                friendId:fid
            },function(result) {
                $this.removeClass("unfollow").text("+关注");
                $this.attr("data-isFollow","false");   
            },function(result){
                CLUB.alert.error(result.message);
            });
        });
        $(".dongtai-user-face .follow[data-isFollow=false]").live("click",function(){
            if(!CLUB.global.isLogin){
                CLUB.login.showDialog();
                return ;
            }
            var $this = $(this);
            var fid=$this.parent(".dongtai-user-face").attr("data-userId");
            CLUB.ajax.post(CLUB.global.ROOT+"/intf/focus.jsp",{
                act:"add",
                accountId:CLUB.global.userId,
                friendId:fid
            },function(result) {
                $this.addClass("unfollow").text("取消关注");
                $this.attr("data-isFollow","true"); 
            },function(result){
                CLUB.alert.error(result.message);
            });
        });
         window.onscroll = function() {
             if (CLUB.dyna.isPageBottom()) {
                 CLUB.clubIndex.dyna.getList();
             }
         }
    },
   isPageBottom: function() {
            var scrollTop = 0;
            var clientHeight = 0;
            var scrollHeight = 0;
            if (document.documentElement && document.documentElement.scrollTop) {
                scrollTop = document.documentElement.scrollTop;
            } else if (document.body) {
                scrollTop = document.body.scrollTop;
            }
            if (document.body.clientHeight && document.documentElement.clientHeight) {
                clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight: document.documentElement.clientHeight;
            } else {
                clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight: document.documentElement.clientHeight;
            }
            // 知识点：Math.max 比较大小，取最大值返回
            scrollHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
            if (scrollTop + clientHeight == scrollHeight) {
                return true;
            } else {
                return false;
            }
        },
    checkIsFocus:function(){
        var url = CLUB.global.BIPROOT+"/intf/focus.jsp?callback=?&accountId="+CLUB.global.userId+"&act=isHisFocus";
        var flag = false;
        $(".dongtai-user-face[data-isChecked=false]").each(function(){
            url+="&friendIds="+$(this).attr("data-userId");
            flag = true;
        });
        if(flag){
            CLUB.ajax.jsonp(url, {}, function(data){
                $(".dongtai-user-face").each(function(){
                    if(data[$(this).attr("data-userId")]==1){
                        //关注的人
                        var $a = $(this).find(".follow");
                        $a.addClass("unfollow").text("取消关注");
                        $a.attr("data-isFollow","true");
                    }
                    $(this).attr("data-isChecked","true");
                });
            });
        }
    },
    initImages:function(){
        CLUB.dyna.picture.init(CLUB.global.oClubId, CLUB.global.BBSROOT, 
            CLUB.global.BBSROOT+'/plugins/autoclub/getImagesByTid.do',
            CLUB.global.ROOT+'/brand/dyna/getDynaImages.do');
    }
};
CLUB.namespace("dyna.picture");
CLUB.dyna.picture={
    curIndex : 0,
    picSeq : 0,
    $cover : null,
    $tips : null,
    topicLink : '',
    picData:"",
    picCount:0,
    $box:$('<a href="javascript:;" class="photos-close"></a>'+  
        '<div title="上一张" class="photos-prevWrap"><a href="javascript:void(0)" class="photos-prev"></a></div>'+
        '<div title="下一张" class="photos-nextWrap"><a href="javascript:void(0)" class="photos-next"></a></div>'+
        '<div id="j-photos-box" class="photos-box">'+                                             
        '<div class="photos-bd">'+                            
        '<div style="text-align:center;" class="photos-img"><img src="http://www.pcauto.com.cn/blank.gif" /></div>'+
        '</div>'+
        '<div class="photos-hd">'+
        '<div class="mark"><span class="photos-index"></span>/<span class="photos-num"></span></div>'+
        '<div class="subMark"><a style="display:none;" class="photo-link" href="#" target="_blank">查看详细帖子&gt;&gt;</a></div>'+
        '</div>'+
        '</div>'),
    init:function(oClubId,bbsROOT,bbsURL,dynaURL){
        $('.dontai-pics .item').live('click',function(){
            // seq
            CLUB.dyna.picture.picSeq = $(this).attr('data-seq');
            // 首次点击
            CLUB.dyna.picture.$cover = $('<div class="photos-cover"></div>');
            CLUB.dyna.picture.$tips = $('<div class="photos-tips">数据加载...</div>');
            $('body').append(CLUB.dyna.picture.$cover);
            $('body').append(CLUB.dyna.picture.$tips);
            CLUB.dyna.picture.$cover.fadeIn(300);
            CLUB.dyna.picture.$cover.css({
                'height':$('body').height()+'px'
            });
            CLUB.dyna.picture.$tips.css({
                'top':$(document).scrollTop()+($(window).height()-50)/2 + 'px'
            });
            var url = '',//接口地址
            id = 0;
            if( $(this).parent().attr('data-topicId') && $(this).parent().attr('data-topicId')>0 ){
                //帖子
                id = parseInt($(this).parent().attr('data-topicId'));
                url = bbsURL+'?topicId='+id+'&callback=CLUB.dyna.picture.fnPhotos';
                CLUB.dyna.picture.topicLink = bbsROOT+'/topic-'+id+'.html';
            }else{
                // 动态
                id = parseInt($(this).parent().attr('data-id'));
                url = dynaURL+'?dynaInfoId='+id+'&oClubId='+oClubId+'&callback=CLUB.dyna.picture.fnPhotos';
            }
            var s = document.createElement('script');
            s.src = url;
            document.getElementsByTagName('head')[0].appendChild(s);
        });
    },
    boxRemove:function(){
        $('#j-photos-box,.photos-cover').fadeOut(300,function(){
            CLUB.dyna.picture.$cover.remove();
            CLUB.dyna.picture.$tips.remove();
            CLUB.dyna.picture.$box.remove();
            CLUB.dyna.picture.topicLink = '';
            CLUB.dyna.picture.curIndex = 0;
        })        
    },
    btnCtrl:function(){
        $('.photos-prevWrap,.photos-nextWrap').show();
        if(CLUB.dyna.picture.curIndex==0){
            $('.photos-prevWrap').hide();
        }
        if(CLUB.dyna.picture.curIndex==(CLUB.dyna.picture.picCount-1)){
            $('.photos-nextWrap').hide();
        }
    },
    loadImg:function(url,callback){
        $('#j-photos-box img').attr('src','http://www.pcauto.com.cn/blank.gif');
        var _img = new Image();
        _img.onload = function(){
            _img.onload=null;
            var h = this.height;
            var w = this.width;
            callback(w,h,url);
        }
        _img.src = url;
    },
    changePic:function(picW,picH,url){
        CLUB.dyna.picture.$tips.hide();
        var hRatio;
        var wRatio;
        var Ratio = 1;
        var maxWidth=$(window).width()-200;
        var maxHeight=$(window).height()-200;
        var w =picW;
        var h =picH;
        if(w<200){
            h=(h/w)*200;
            w=200;
        }
        wRatio = maxWidth / w;
        hRatio = maxHeight / h;
        if (maxWidth ==0 && maxHeight==0){
            Ratio = 1;
        }else if (maxWidth==0){//
            if (hRatio<1) Ratio = hRatio;
        }else if (maxHeight==0){
            if (wRatio<1) Ratio = wRatio;
        }else if (wRatio<1 || hRatio<1){
            Ratio = (wRatio<=hRatio?wRatio:hRatio);
        }
        if (Ratio<1){
            w = w * Ratio;
            h = h * Ratio;
        }

        var target = $('#j-photos-box'),fix_h = 0;
        target.find('.photos-img img').attr({
            'src':url,
            'height':h
        });
        fix_h = h+42;

        var fix_w = 0;
        target.find('.photos-img img').attr({
            'src':url,
            'width':w
        });
        fix_w = w;
       
        target.css({
            'top': ($(window).height()-fix_h)/2 + 'px',
            'height':fix_h+'px',
            'width':fix_w,
            'marginLeft':'-'+fix_w/2+'px'
        });
        $('.photos-nextWrap,.photos-prevWrap').css({
            'height':h+'px',
            'top': ($(window).height()-fix_h)/2+10 + 'px',
            'width':w/2+'px'
        });

        target.find('.photos-num').text(CLUB.dyna.picture.picCount);
        target.find('.photos-index').text(CLUB.dyna.picture.curIndex+1);
        if(CLUB.dyna.picture.topicLink){
            target.find('.photo-link').show().attr('href',CLUB.dyna.picture.topicLink);
        }
        target.show();
    },
    fnPhotos:function(json){
        $.each(json,function(n,v){
            if(v.seq ==CLUB.dyna.picture.picSeq){
                CLUB.dyna.picture.curIndex = n;
                return false;
            }
        });
        CLUB.dyna.picture.picData = json;
        CLUB.dyna.picture.picCount = CLUB.dyna.picture.picData.length;
        // 无数据
        if(CLUB.dyna.picture.picCount==0||CLUB.dyna.picture.curIndex>CLUB.dyna.picture.picCount-1){
            CLUB.dyna.picture.$tips.text('暂无大图数据');
            setTimeout(function(){
                CLUB.dyna.picture.$cover.remove();
                CLUB.dyna.picture.$tips.remove();
                CLUB.dyna.picture.curIndex = 0;
                CLUB.dyna.picture.topicLink = '';
            },300);
            return;
        }
  
        //load
        CLUB.dyna.picture.loadImg(CLUB.dyna.picture.picData[CLUB.dyna.picture.curIndex].url,function(picW,picH,url){
            $('body').append(CLUB.dyna.picture.$box);
            CLUB.dyna.picture.changePic(picW,picH,url);
            CLUB.dyna.picture.btnCtrl();
            // next
            $('.photos-nextWrap').click(function(){
                if( CLUB.dyna.picture.curIndex==(CLUB.dyna.picture.picCount-1) ) return;
                CLUB.dyna.picture.curIndex++;
                CLUB.dyna.picture.btnCtrl();
                CLUB.dyna.picture.loadImg(CLUB.dyna.picture.picData[CLUB.dyna.picture.curIndex].url,function(picW,picH,url){
                    CLUB.dyna.picture.changePic(picW,picH,url);
                })
            });
            //prev
            $('.photos-prevWrap').click(function(){
                if(CLUB.dyna.picture.curIndex==0) return;
                CLUB.dyna.picture.curIndex--;
                CLUB.dyna.picture.btnCtrl();
                CLUB.dyna.picture.loadImg(CLUB.dyna.picture.picData[CLUB.dyna.picture.curIndex].url,function(picW,picH,url){
                    CLUB.dyna.picture.changePic(picW,picH,url);
                })
            });
            // close
            $('.photos-close,.photos-cover').click(function(){
                CLUB.dyna.picture.boxRemove();
            }); 
            // 键盘触发
            $(document).keydown(function(e){
                switch(e.keyCode){
                    case 27:
                        CLUB.dyna.picture.boxRemove();
                        break;
                }
            });
        })
    }
}
//动态回复模块
CLUB.namespace("reply");
CLUB.reply={
    isReplying:false,
    init:function(){
        if(CLUB.global.loading("isInitingReply")){
            return;
        }
        $(".pinglun").live("click",function(){
            var dynaInfoId = $(this).attr("data-dynaInfoId");
            if($(this).attr("isLoadingReply")==="true"){
                return;
            }
            if($(this).attr("isShowReplyList")==="true"){
                $("div[data-replyList="+dynaInfoId+"] .replyData").remove();
                $(this).attr("isShowReplyList","false");
                return ;
            }
            $(this).attr("isLoadingReply","true");
            $(this).attr("isShowReplyList","true");
            var topicId= $(this).attr("reply-topicId"),forumId=$(this).attr("reply-forumId"),userId=$(this).attr("data-createBy");
            var dynaType = $(this).attr("data-dynaType");
            var activityId = $(this).attr("reply-activityId");
            if(!topicId){
                topicId=0;
            }
            if(!forumId){
                forumId=0;
            }
            if(!userId){
                userId=0;
            }
            if(!dynaType){
                dynaType=0;
            }
            if(!activityId){
                activityId=0;
            }
            CLUB.clubIndex.reply.getList(dynaInfoId,topicId,forumId,userId,dynaType,activityId);
        });
        $("input[name=reply]").live("keyup",function(){
            CLUB.reply.initBtnStyle($(this));
        });
    },
    initBtnStyle:function($input){
        var val = $input.val();
        var $btn = $input.parent(".replyData-inp").next().find(".reply-btn");
        if(val==""){
            $btn.attr("class","reply-btn reply-btn-disable");
        }else{
            $btn.attr("class","reply-btn");
        } 
    },
    replyToDyna:function(node){
        var data = {
            dynaInfoId:$(node).attr("data-dynaInfoId"),
            dynaReplyId:$(node).attr("data-dynaReplyId"),
            oClubId:$(node).attr("data-oClubId"),
            postToUserId:$(node).attr("data-postToUserId"),
            postToNickName:$(node).attr("data-postToNickName")
        };
        var $content = $(node).parents(".replyData-tool").prev().find('input');
        var content = CLUB.emotion.transformToUBB($content.val());
        if(!CLUB.reply.checkContent($content)){
            return ;
        }
        if(!CLUB.global.isLogin){
            CLUB.login.showDialog();
            return ;
        }
        if(CLUB.reply.isReplying){
            return ;
        }
        CLUB.reply.isReplying = true;
        data.UCROOT=CLUB.global.UCROOT;
        data.userId=CLUB.global.userId;
        data.nickName=CLUB.global.nickName;
        data.userAvatar=CLUB.common.faceSizeUrl(data.userId, 50);
        data.content=content;
        data.createDate=$(node).parents(".dontai").attr("data-createDate");
        CLUB.ajax.post("/dyna/replyDyna.do",{
            oClubId:data.oClubId,
            dynaInfoId:data.dynaInfoId,
            postToDynaReplyId:data.dynaReplyId,
            content:data.content,
            createDate:data.createDate
        },function(rs){
            data.content = CLUB.emotion.transformToHTML(rs.data.content);             
            $(node).parents('.replyData').find(".replyData-list").prepend(template("template-dynaReplyListItem",data));
            CLUB.reply.successTip();
            $content.val("");//清空
            CLUB.clubIndex.reply.updateReplyCount(data.dynaInfoId);
            CLUB.reply.isReplying = false;
        },function(rs){
            CLUB.alert.error(rs.message);
            CLUB.reply.isReplying = false;
        });
    },
    replyToTopic:function(node){
        var data = {
            postToUserId:$(node).attr("data-postToUserId"),
            topicId:$(node).attr("data-topicId"),
            forumId:$(node).attr("data-forumId"),
            postToNickName:$(node).attr("data-postToNickName"),
            dynaInfoId:$(node).attr("data-dynaInfoId"),
            postToPostId:$(node).attr("data-postId")
        };
        var $content = $(node).parents(".replyData-tool").prev().find('input');
        var content = CLUB.emotion.transformToUBB($content.val());
        if(!CLUB.reply.checkContent($content)){
            return ;
        }
        if(!CLUB.global.isLogin){
            CLUB.login.showDialog();
            return ;
        }
        if(CLUB.reply.isReplying){
            return ;
        }
        CLUB.reply.isReplying = true;
        data.UCROOT=CLUB.global.UCROOT;
        data.userId=CLUB.global.userId;
        data.nickName=CLUB.global.nickName;
        data.userAvatar=CLUB.common.faceSizeUrl(CLUB.global.userId, 50);
        data.content=content;
        data.createDate=$(node).parents(".dontai").attr("data-createDate");
        $.post("/bbs/action/post/create.ajax",{
            tid:data.topicId,
            message:data.content,
            fid:data.forumId,
            replyToId:data.postToPostId,
            sendMsg:true
        },function(rs){
        	if(rs.status==0){
	        	CLUB.reply.successTip();
	            var ind = rs.message.indexOf("[/quote]");
	            var msg = rs.message;
	            if(ind>0){
	                msg = rs.message.substr(ind+"[/quote]".length,rs.message.length);
	            }
	            var appContent = CLUB.emotion.transformToHTML(msg.length>150?msg.substring(0,150)
	                +"...<a target='_blank' href='"+CLUB.global.BBSROOT+"/post-"+rs.tid+"_"+rs.pid+".html'>详细</a>":msg);
	            data.content=appContent;
	            $(node).parents('.replyData').find(".replyData-list").prepend(template("template-dynaReplyListItem",data));
	            $content.val("");//清空
	            CLUB.clubIndex.reply.updateReplyCount(data.dynaInfoId);
	            CLUB.reply.isReplying = false;
        }else{
        	CLUB.alert.error(rs.desc);
            CLUB.reply.isReplying = false;
        }
            
        },"json");
    },
    successTip:function(){
        $("#Jsuccess-txt").html("回复成功");
        $("#Jsuccess").css({
            marginLeft:-$("#Jsuccess").width()/2
        }).show();
        setTimeout(function(){
            $('#Jsuccess').hide();
        },1500) 
    },
    showReplyBtn:function(node){
        var $inner = $(node).parents("dd[data-reply-reply]").find(".replyData-inner");
        if($inner.length>0){
            $inner.remove();
        }else{
            var data={
                topicId:$(node).attr("data-topicId"),
                forumId:$(node).attr("data-forumId"),
                dynaInfoId:$(node).attr("data-dynaInfoId"),
                dynaReplyId:$(node).attr("data-dynaReplyId"),
                postToUserId:$(node).attr("data-postToUserId"),
                postToNickName:$(node).attr("data-postToNickName"),
                postId:$(node).attr("data-postId"),
                oClubId:$(node).attr("data-oClubId"),
                showFunction:'CLUB.emotion.showInReply(this)',
                selectFunction:"CLUB.emotion.selectInReply(this)"
            };
            var html = template("template-dynaReplyReply",data);
            $(node).parents("dd[data-reply-reply]").append(html);
        }
    },
    checkContent:function($content){
        if($content.val().replace(/(^\s*)|(\s*$)/g, "")==""){
            return false;
        }
        //TODO 长度判断
        return true;
    }
};

//统计相关模块
CLUB.namespace("stat");
CLUB.stat={
    visitPage:function(){
        if(CLUB.global.isLogin){//访客记录
            CLUB.ajax.post(CLUB.global.ROOT+"/brand/stat/addVisitor.do",{
                oClubId:CLUB.global.oClubId
            });
        }
        //人气记录
        CLUB.ajax.post(CLUB.global.ROOT+"/brand/stat/addPv.do",{
            oClubId:CLUB.global.oClubId
        });
    }
}

//登录相关模块
CLUB.namespace("login");
CLUB.login={
    showDialog:function(){
        CLUB.alert._show({
            name:"login"
        });
    },
    submit:function(){
        if($("input[name='username']").val() == "用户名/邮箱/手机号") {
            $(".rTips").html("用户名和密码必须输入");
            return false;
        }
        if($("input[name='password']").val() == "") {
            $(".rTips").html("用户名和密码必须输入");
            return false;
        }
        if ($("#checaptcha").val() == "") {
            $(".rTips").html("请输入验证码");
            return false;
        } else {
            $("#loginForm input[name=return]").val(window.location.href);
            $("#loginForm").submit();
        }
    }
};

CLUB.namespace("phone");
CLUB.phone={
	isBinding : false,
    showDialog:function(){
        var defaultTip = $("#bindPhoneForm .txt").attr("data-defaultTxt");
        $("#bindPhoneForm .txt").text(defaultTip);
        CLUB.alert._show({
            name:"bind-phone",
            closeMask:true
        });
    },
    hideDialog:function(){
        CLUB.alert._hide({
            name:'bind-phone',
            closeMask:true
        })
    },
    bind:function(){
        var defaultTip = $("#bindPhoneForm .txt").attr("data-defaultTxt");
        var mobile = $("#bindPhoneForm input[name=phone]").val();
        if(mobile != null) {
            mobile = $.trim(mobile);
        }
        if(!(/^(13|14|15|18|17)[0-9]{9}$/.test(mobile))){
            $("#bindPhoneForm .txt").text("请输入正确的手机号码");
            return ; 
        } else {
            $("#bindPhoneForm .txt").text(defaultTip);
        } 
        var code = $("#bindPhoneForm input[name=code]").val();
        if (code=="") {
            $("#bindPhoneForm .txt").text("请输入验证码");
            return ; 
        }else if(code.length != 6 ){
            $("#bindPhoneForm .txt").text("请输入正确的验证码");
            return ; 
        }else{
            $("#bindPhoneForm .txt").text(defaultTip);
        }
        if(CLUB.phone.isBinding){
        	return;
        }
        CLUB.phone.isBinding = true;
        CLUB.ajax.post($("#bindPhoneForm").attr("action"),$("#bindPhoneForm").serialize(),function(rs){
        	CLUB.phone.isBinding = false;
            CLUB.phone.hideDialog();
            CLUB.member.joinClub()
        }, function(rs){
            $("#bindPhoneForm .txt").text(rs.message);
            CLUB.phone.isBinding = false;
        });
    },
    canSendVCode:true,
    initCountDown:function(){
        $("#get-code").live("click",function(){
            if(CLUB.phone.canSendVCode){
                CLUB.phone.sendVCode();
            }
            var em=this;
            if(em.className=="get-code"){
                CLUB.phone.canSendVCode = false;
                em.className="get-code disable";
                em.innerHTML="验证码发送中...";
                var time=59;
                var djs=setInterval(function(){
                    if(time>=0){
                        em.innerHTML=time+"秒后可重新获取";
                        time--;
                    }else{
                        clearInterval(djs);
                        CLUB.phone.canSendVCode = true;
                        em.className="get-code";
                        em.innerHTML="重新获取验证码";
                    }
                },1000);
            }
        });
    },
    sendVCode:function(){
    	var mobile = $("#bindPhoneForm input[name=phone]").val();
	        if(mobile != null) {
	            mobile = $.trim(mobile);
	        }
    	if(!(/^(13|14|15|18|17)[0-9]{9}$/.test(mobile))){
	            $("#bindPhoneForm .txt").text("请输入正确的手机号码");
	            return ; 
	        } 
        CLUB.ajax.get(CLUB.global.ROOT+"/club/getVCodeKey.do",{},function(data){
            var vCodeKey = data.vCodeKey;
            var vCodeTime = data.vCodeTime;
            $.ajax({
                type: "POST",//暂时用不到这个功能———— nginx需要配置，还没测试过发验证码功能
                url: CLUB.global.ROOT+"/passport/sendVerificationCode.jsp?type=autoClub&act=getPassword&mobile=" + mobile + "&vCodeKey="+vCodeKey+"&VCodeTime="+vCodeTime,
                data: "{}",
                success: function(returnStr){
                    returnStr = returnStr.replace(/\n|\r/g,'');
                    var data = eval("("+returnStr+")"); //转换为json对象 
                    if(data.code == undefined) {//如果返回没有code信息当做失败处理
                        $("#bindPhoneForm .txt").text("验证码发送失败，请稍后重新点击发送");
                    } else if(data.code == 0){
                        $("#bindPhoneForm .txt").text("验证码已发送到您的手机");
                    } else {
                        if(data.code == -1 || data.code == -2) {
                            $("#bindPhoneForm .txt").text(data.message);
                        }
                    }
                },
                error: function(){
                    $("#bindPhoneForm .txt").text("验证码发送失败，请稍后重新点击发送");
                }
            });
        },function(rs){
            CLUB.alert.error(rs.message);
        });
    }
}
//会员操作相关
CLUB.namespace("member");
CLUB.member={
    joinClub:function(){
        if(!CLUB.global.isLogin){
            CLUB.login.showDialog();
            return ;
        }
        if(CLUB.global.isUserLock){
	        	CLUB.alert.error("您所绑定的手机号码已经被该车友会封锁,请在个人中心更改绑定的手机号码！");
	        	return false;
	    }
        CLUB.ajax.post(CLUB.global.ROOT+"/brand/member/joinClub.do", {
            oClubId:CLUB.global.oClubId
        }, function(rs){
            CLUB.alert.successCall(rs.message,"CLUB.common.reload()");
        }, function(rs){
            CLUB.alert.error(rs.message);
        //CLUB.phone.showDialog();
        });
    },
    joinClubByBindPhone:function(){

    	if(!CLUB.global.isLogin){
            CLUB.login.showDialog();
            return ;
        }
    	if(!CLUB.global.isUserBindPhone){
        	CLUB.phone.showDialog();
        	return;
        }
        CLUB.member.joinClub();
    },
    applyForClub:function(){
        CLUB.ajax.post(CLUB.global.ROOT+"/brand/member/applyForClub.do", {
            oClubId:CLUB.global.oClubId
        }, function(rs){
            CLUB.alert.success(rs.message);
        }, function(rs){
            CLUB.alert.error(rs.message);
        });
    },
    canApplyForClub:function(){
        if(!CLUB.global.isLogin){
            CLUB.login.showDialog();
            return ;
        }
        CLUB.ajax.post(CLUB.global.ROOT+"/brand/member/canApplyForClub.do", {
            oClubId:CLUB.global.oClubId
        }, function(rs){
            if(rs.isShowConfirm ==1){
                CLUB.alert.confirm(rs.message, "CLUB.member.applyForClub()");
            }else{
                CLUB.alert.success(rs.message);
            }
        }, function(rs){
            CLUB.alert.error(rs.message);
        });
        
    }
}

//首页JS初始化
CLUB.namespace("clubIndex.init");
CLUB.clubIndex.init={
    clubActivity:function(){
        if($('#tab .contentdiv').length>0){
            CLUB.common.initSlide($('#tab .contentdiv'),$('#tab .pagination .toc'),$('#tab .contentdiv img'));
            if($('#tab .contentdiv').length==1){
                $('#tab .toc').css('height','0');
            }
            else{
                $('#tab .toc').css('height','10px');
            }
        }
    },
    focusImg:function(){
        if($('.mainfocus .slider_view li').length>=2){
            var m=0,n=0;
            var mainfocus = new Slide({
                target: $('.mainfocus .slider_txt li'),
                control:  false,
                effect: 'fade'
            });
            new Slide({
                control: $('.mainfocus .slider_thumb li.toc'),
                target:  $('.mainfocus .slider_view li'),
                effect: 'fade',
                autoPlay: true,
                stay: 5000,
                onchange: function(){
                    mainfocus.playTo(this.curPage)
                    var num = $('.mainfocus .slider_view li').length;
                    var thumb = $('.mainfocus .slider_thumb img');
                    var thumbImg = thumb.length;
                    if(m<num){
                        var nli = this.target[this.curPage].getElementsByTagName("img")[0];
                        if(nli.getAttribute("#src")) {
                            nli.src = nli.getAttribute("#src");
                            nli.removeAttribute("#src");
                        }
                    }
                    m++;
                    if(n<1){
                        for(var i = 0;i<thumbImg;i++){
                            if(thumb[i].getAttribute("#src")){
                                thumb[i].src = thumb[i].getAttribute("#src");
                                thumb[i].removeAttribute("#src");
                            }
                        }
                        n++;
                    }
                }
            });
        }else{
            $('.mainfocus .slider_view img').attr('src',$('.mainfocus .slider_view img').attr('#src'));
        }
    },
    adminMenu: function(){
        if(CLUB.global.isClubAdmin){
            //置顶取消
            $("a.delete[data-isTop=true]").live("click",function(){
                var dynaInfoId = $(this).attr("data-dynaInfoId");
                var tip = "您确定要取消该置顶动态？";
                CLUB.alert.confirm(tip, 'CLUB.clubIndex.dyna.cancelTop('+dynaInfoId+')');
            });
            //动态删除
            $("a.delete[data-isTop=false]").live("click",function(){
                var type = $(this).attr("data-type");
                var dynaInfoId = $(this).attr("data-dynaInfoId");
                var tip = "动态删除后无法恢复，您确定要删除？";
                if(type==CLUB.global.dynaType.picture){
                    tip = '动态删除后无法恢复，但不会删除相册中的照片，您确定要删除？';
                }
                CLUB.alert.confirm(tip, 'CLUB.clubIndex.dyna.del('+dynaInfoId+')');
            });
            //其他管理操作
            $(".banner .club-logo-r,.mainfocus,.club-main-info .des,.ul-txt-list li,.gonggao,.dontai-operate")
            .live('mouseenter',function(){
                $(this).addClass("hover");
            }).live('mouseleave',function(){
                $(this).removeClass("hover");
            });
        }
    },
    all:function(){
        CLUB.clubIndex.init.focusImg();
        CLUB.clubIndex.init.clubActivity();
        CLUB.stat.visitPage();
        //CLUB.phone.initCountDown();
        CLUB.clubIndex.dyna.postComment.init();
        CLUB.clubIndex.dyna.postQuestion.init();
        CLUB.clubIndex.dyna.getList();
        CLUB.clubIndex.dyna.initPraise();
        CLUB.clubIndex.dyna.getTopList();
        CLUB.reply.init();
        CLUB.clubIndex.init.adminMenu();
        CLUB.dyna.initFocus();
        CLUB.dyna.initImages();
    }
};

//首页动态列表
CLUB.namespace("clubIndex.dyna");
CLUB.clubIndex.dyna={
    add:function(data){
        data.clubUrl=CLUB.global.clubUrl;
        data.ROOT = CLUB.global.ROOT;
        data.clubName=CLUB.global.clubName;
        data.BBSROOT=CLUB.global.BBSROOT;
        data.UCROOT=CLUB.global.UCROOT;
        data.oClubId=CLUB.global.oClubId;
        data.isClubAdmin=CLUB.global.isClubAdmin;
        data.content = CLUB.emotion.transformToHTML(data.content);
        $("#clubDynaList").prepend(template(data.templateId, data));	
        Lazy.create(globalLazy);
    },
    getList:function(){
        if(CLUB.global.loading("isLoadingDynaList") || CLUB.global.isOverData()){
            return;
        }
        CLUB.global.loading("isLoadingDynaList",true);
        var pageSize = 10;
        var pageNo = CLUB.global.addPageNo("dynaListPageNo");
        var t = new Date().getTime();
        CLUB.ajax.get(CLUB.global.ROOT+"/brand/dyna/getDynaListByClubId.do?oClubId="+CLUB.global.oClubId+"&pageNo="+pageNo+"&_t="+t, {needToViewUrl:1}, function(d){
            var list = d.data.list;
            if(list.length==0 || list.length<pageSize){
                CLUB.global.isOverData(true);
                $("#loadMoreDynaList").hide();
            }
            var idsStr = "";
            for(var i=0,len=list.length;i<len;i++){
                list[i].clubUrl=CLUB.global.clubUrl;
                list[i].ROOT = CLUB.global.ROOT;
                list[i].clubName=CLUB.global.clubName;
                list[i].BBSROOT=CLUB.global.BBSROOT;
                list[i].UCROOT=CLUB.global.UCROOT;
                list[i].oClubId=CLUB.global.oClubId;
                list[i].isClubAdmin=CLUB.global.isClubAdmin;
                list[i].content = CLUB.emotion.transformToHTML(list[i].content);
                if(list[i].templateId == ""){
					console.log("not templateId : "+list[i].dynaInfoId);
					continue;
				}
                $("#clubDynaList").append(template(list[i].templateId, list[i]));
                //清除已置顶的按钮
                if($("#topClubDyna-"+list[i].dynaInfoId).length>0){
                    $("#setTopBtn-"+list[i].dynaInfoId).remove();
                }
                idsStr+=list[i].dynaInfoId+",";
            }
            if(CLUB.global.isLogin){
                //设置已点赞的
                CLUB.ajax.get(CLUB.global.ROOT+"/brand/dyna/getPraiseList.do",{
                    dynaInfoIds:idsStr
                },function(rs){
                    var list = rs.data.list;
                    for(var i=0,len = list.length;i<len;i++){
                        $(".btn-zan[data-dynaInfoId='"+list[i].dynaInfoId+"']").addClass("btn-zan-active").attr("data-isClick","true");
                    }
                });
                CLUB.dyna.checkIsFocus();
            }
            Lazy.create(globalLazy);
            CLUB.global.loading("isLoadingDynaList",false);
        });
    },
    getTopList:function(){
        var t = new Date().getTime();
        CLUB.ajax.get(CLUB.global.ROOT+"/brand/dyna/getTopList.do?oClubId="+CLUB.global.oClubId+"&_t="+t, {needToViewUrl:1}, function(d){
            var list = d.data.list;
            if(list.length==0){
                $("#topDynaList").html("");
            }else{
                for(var i=0,len=list.length;i<len;i++){
                    list[i].clubUrl=CLUB.global.clubUrl;
                list[i].ROOT = CLUB.global.ROOT;
                list[i].clubName=CLUB.global.clubName;
                list[i].BBSROOT=CLUB.global.BBSROOT;
                list[i].UCROOT=CLUB.global.UCROOT;
                list[i].oClubId=CLUB.global.oClubId;
                list[i].isClubAdmin=CLUB.global.isClubAdmin;
                list[i].isTop = true;
                list[i].content = CLUB.emotion.transformToHTML(list[i].content);
                 if(list[i].templateId == ""){
					console.log("not templateId : "+list[i].dynaInfoId);
					continue;
				}
                 $("#topDynaList").append(template(list[i].templateId, list[i]));
                }
                topDynaHover();
            }
        });
        function topDynaHover(){
            $(".dontai-operate").live('mouseenter',function(){
                $(this).addClass("hover");
            }).live('mouseleave',function(){
                $(this).removeClass("hover");
            });
             Lazy.create(globalLazy);
        }
    },
    del:function(dynaInfoId){
        CLUB.alert.hide(true);
        if(CLUB.common.checkAdmin()){
            CLUB.ajax.post(CLUB.global.ROOT+"/brand/dyna/deleteDyna.do", {
                oClubId:CLUB.global.oClubId,
                dynaInfoId:dynaInfoId
            }, function(rs){
                $("#dynaInfoDiv-"+dynaInfoId).parent().remove();
                $("#topClubDyna-"+dynaInfoId).remove();
                CLUB.alert.success(rs.message);
            }, function(rs){
                CLUB.alert.error(rs.message);
            });
        }
    },
    setTop:function(dynaInfoId){
        if(CLUB.common.checkAdmin()){
            CLUB.ajax.post(CLUB.global.ROOT+"/brand/dyna/top.do", {
                oClubId:CLUB.global.oClubId,
                dynaInfoId:dynaInfoId
            }, function(rs){
               location.reload();
            },function(rs){
                CLUB.alert.error(rs.message);
            });
        }
    },
    cancelTop:function(dynaInfoId){
        CLUB.alert.hide(true);
        if(CLUB.common.checkAdmin()){
            CLUB.ajax.post(CLUB.global.ROOT+"/brand/dyna/cancelTop.do", {
                oClubId:CLUB.global.oClubId,
                dynaInfoId:dynaInfoId
            }, function(rs){
                location.reload();
            }, function(rs){
                CLUB.alert.error(rs.message);
            });
        }
    },
    initPraise:function(){
        CLUB.dyna.initPraise();
    }
};
//首页发说说
CLUB.namespace("clubIndex.dyna.postComment");
CLUB.clubIndex.dyna.postComment={
    process:"&command=53003&command=53004&command=53016&command=53017&command=53018&command=53019&command=53020",
    uploadType:"image",
    flashId:"l_571x167_llx",
    flashUrl:"http://www1.pcauto.com.cn/flash/141226/cheyouhui/l_571x167_llx.swf?" + new Date().getTime(),
    flashWidth:571,
    flashHeight:167,
    getProcess:function() {
        return CLUB.clubIndex.dyna.postComment.process;
    },
    flashInitReady:false,
    flashInit : function(){
        var pc = CLUB.upload.initProcCommand("-quality 80");
        CLUB.upload.thisMovie(CLUB.clubIndex.dyna.postComment.flashId).sendToActionScript(pc);
        CLUB.clubIndex.dyna.postComment.flashInitReady=true;
    },
    getPictureNum:function() {
        if(CLUB.clubIndex.dyna.postComment.flashInitReady){
            return CLUB.upload.thisMovie(CLUB.clubIndex.dyna.postComment.flashId).getPictureNum();
        }else{
            return 0;
        }
    },
    imagesjson:"",
    isSend:false,
    alertErrorTip:function(txt){
        CLUB.alert.error(txt, false, "知道了");
    },
    checkContent:function(str1,str2){
        return str1 || str2;
    },
    commit:function(){//发表说说
        if(CLUB.clubIndex.dyna.postComment.isSend){
            CLUB.clubIndex.dyna.postComment.alertErrorTip("请不要重复提交!");
            return;
        }
        var content = $("#publish-box1 textarea").val();
        content = content=="说说今天的身边事…" ? "" :content;
        content = CLUB.emotion.transformToUBB(content);
        var len= content.length;
        if(!CLUB.clubIndex.dyna.postComment.checkContent(content,CLUB.clubIndex.dyna.postComment.imagesjson)){
            CLUB.clubIndex.dyna.postComment.alertErrorTip("请先输入内容!");
            return;
        }
        if(len>300){
            CLUB.clubIndex.dyna.postComment.alertErrorTip("说说内容长度不能超过300字");
            return ;
        }
        CLUB.clubIndex.dyna.postComment.isSend = true;
        CLUB.ajax.post(CLUB.global.ROOT+"/brand/dyna/createCommentDyna.do",{
            content:content,
            images:CLUB.clubIndex.dyna.postComment.imagesjson,
            oClubId:CLUB.global.oClubId,
            fromType:0
        },function(rs){
            CLUB.clubIndex.dyna.postComment.isSend = false;
            CLUB.clubIndex.dyna.postComment.closeBox();
            CLUB.alert.success("发表成功");
            CLUB.clubIndex.dyna.add(rs.data);
        },function(rs){
            CLUB.clubIndex.dyna.postComment.isSend = false;
            CLUB.clubIndex.dyna.postComment.alertErrorTip(rs.message);
        });
    },
    upcAfter:function(imgData){
        //转换图片为json集合,一张图片一个json字符串
        var imagesjson = "[";
        var j = 0;
        for(var i = 0; i < imgData.length; i++){
            if(imgData[i].url.indexOf("1024x1024")!=-1){
                imagesjson += "{\"url\":\""+imgData[i].url+"\",\"seq\":"+(j+1)+",width:"+imgData[i].width+",height:"+imgData[i].height+"}";
                j++;
            }
        }
        imagesjson +="]";
        CLUB.clubIndex.dyna.postComment.imagesjson = imagesjson;
    },
    initFlash : function(divId) {
        var flashVars = "useExternalInterface=Yes&process=" + encodeURIComponent( CLUB.clubIndex.dyna.postComment.process) 
        +"&transactionUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/tx.jsp?application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT) 
        +"&uploadUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/upload_stream_flash.jsp?fileType=Picture&application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT)
        +"&flashWidth=" + encodeURIComponent( CLUB.clubIndex.dyna.postComment.flashWidth)
        +"&flashHeight=" + encodeURIComponent( CLUB.clubIndex.dyna.postComment.flashHeight)
        +"&keepSrc="+ encodeURIComponent(true)//保存原图
        +"&color="+ encodeURIComponent("0xFF6600")//框的颜色
        +"&fileSizeLimit="+ encodeURIComponent(10240)//限制文件大小
        +"&upcAfter="+ encodeURIComponent(" CLUB.clubIndex.dyna.postComment.upcAfter")
        +"&getCookie="+ encodeURIComponent("CLUB.upload.getCookie")
        +"&getFileTypes="+ encodeURIComponent("CLUB.upload.getFileTypes")
        +"&flashInit="+ encodeURIComponent(" CLUB.clubIndex.dyna.postComment.flashInit")
        +"&getProcess="+ encodeURIComponent(" CLUB.clubIndex.dyna.postComment.getProcess")
        +"&commit="+ encodeURIComponent(" CLUB.clubIndex.dyna.postComment.commit")
        +"&resizeFlash="+ encodeURIComponent("CLUB.upload.resizeFlash")
        +"&showHide="+ encodeURIComponent("CLUB.upload.showHide")
        +"&flashId="+ encodeURIComponent( CLUB.clubIndex.dyna.postComment.flashId)
        +"&tooltip="+ encodeURIComponent("CLUB.upload.tooltip")
        +"&uploadError="+ encodeURIComponent("CLUB.upload.uploadError")
        
        var flashContent = '<OBJECT id="'+ CLUB.clubIndex.dyna.postComment.flashId+'_ob" name="'+ CLUB.clubIndex.dyna.postComment.flashId+'_ob" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" WIDTH='+ CLUB.clubIndex.dyna.postComment.flashWidth+' HEIGHT='+ CLUB.clubIndex.dyna.postComment.flashHeight+'>'
        + '<PARAM NAME=movie VALUE="'+ CLUB.clubIndex.dyna.postComment.flashUrl+'">'
        + '<PARAM NAME=quality VALUE=high>'
        + '<PARAM NAME=wmode VALUE=transparent>'
        + '<PARAM NAME="allowScriptAccess" value="always">'
        + '<PARAM NAME="FlashVars" VALUE="' + flashVars + '">'
        + '<EMBED  id="'+ CLUB.clubIndex.dyna.postComment.flashId+'_em"  name="'+ CLUB.clubIndex.dyna.postComment.flashId+'_em" src="'+ CLUB.clubIndex.dyna.postComment.flashUrl+'" quality=high wmode="transparent" swLiveConnect=FALSE WIDTH='
        +  CLUB.clubIndex.dyna.postComment.flashWidth + ' HEIGHT='+ CLUB.clubIndex.dyna.postComment.flashHeight
        + ' flashvars="'+ flashVars + '" allowScriptAccess="always" ' 
        + ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>'
        + '</OBJECT>';
        $("#"+divId).html(flashContent);
        return flashContent;
    },
    init:function(){
        if(!CLUB.global.isMember || $("#publish #publish-th").length==0){
            return ;
        }
        $("#publish .publish-txt-login,#publish .publish-btns-ss").click(function(){
            if(!CLUB.upload.isSupportFlash){
                CLUB.alert.error("该设备不支持发表动态",true,"知道了");
                return ;
            }
            if(CLUB.global.mustBindPhone && !CLUB.global.isUserBindPhone){
	        	CLUB.alert.error("您还没有绑定手机,该车友会只有绑定手机后才能互动,请到个人中心绑定手机号码");
	        	return false;
	        }
	        if(CLUB.global.isUserLock){
	        	CLUB.alert.error("您所绑定的手机号码已经被该车友会封锁,请在个人中心更改绑定的手机号码！");
	        	return false;
	        }
            CLUB.alert._maskBg.show();
            var fH=$("#publish").offset();
            var box=$("#publish-box1");
            box.css("left",fH.left+"px");
            box.css("top",fH.top+"px");
            window.scrollTo(0,fH.top-45);
            box.slideDown();
            $("#publish").parent().css("visibility","hidden");
            $("#publish-th").hide();
            $("#publish-box1 .publish-box-face img").animate({
                width:70,
                height:70,
                marginTop:0,
                marginLeft:0,
                borderRadius:36
            }, 500);
            $("#commentContent").focus();
        })
        
        $("#publish-box1 .publish-cancel").click(function(){
            var v = $("#publish-box1 textarea").val();
            if(("说说今天的身边事…"!=v && v.length >0) || CLUB.clubIndex.dyna.postComment.getPictureNum()>0){
                CLUB.alert._show({
                    name:"alert",
                    tip:'未保存的内容将丢失,要继续吗？',
                    btnHtml:'<a class="cancel" href="javascript:void(0)" onclick="CLUB.alert.hide(false)">取消</a><a class="sure" href="javascript:void(0)" onclick="CLUB.clubIndex.dyna.postComment.closeBox()">确定</a>',
                    closeMask:false
                });
            }else{
                CLUB.clubIndex.dyna.postComment.closeBox();
            }
        });
        
        /*统计说说字数*/
        $("#publish-box1 textarea").keyup(function(){
            var l= CLUB.emotion.transformToUBB($(this).val()).length;
            $("#publish-box-textarea-num").html(l+'/300');
            if(l>300){
                $("#publish-box-textarea-num").css("color","red");
            }else{
                $("#publish-box-textarea-num").css("color","#777");
            }
        })
        CLUB.clubIndex.dyna.postComment.initFlash("blish-box-upload-flash");
    }, 
    closeBox:function(){
        $("#publish-box1 .replyData-face").parent().find(".replyData-face-pop").hide();
        CLUB.alert.hide(false);
        $("#publish-box-textarea-num").html('0/300');
        CLUB.clubIndex.dyna.postComment.imagesjson ="";
        $("#publish-box1 textarea").val("说说今天的身边事…");
        $("#publish-box1 .publish-box-face img").animate({
            width:50,
            height:50,
            marginTop:14,
            marginLeft:20,
            borderRadius:25
        }, 500);
        $("#publish").parent().css("visibility","visible");
        $("#publish-box1").slideUp();   
        CLUB.alert._maskBg.hide();
        $("#publish-th").show();
        if(CLUB.upload.isSupportFlash){
            //重新刷新flash（清空ie11 还保持图片的情况）
            CLUB.clubIndex.dyna.postComment.initFlash("blish-box-upload-flash");
        }
    }
}
//发贴
CLUB.namespace("clubIndex.dyna.postTopic");
CLUB.clubIndex.dyna.postTopic={
		postTopic:function(){
			if(CLUB.global.mustBindPhone && !CLUB.global.isUserBindPhone){
	        	CLUB.alert.error("您还没有绑定手机,该车友会只有绑定手机后才能互动,请到个人中心绑定手机号码");
	        	return false;
	        }
	        if(CLUB.global.isUserLock){
	        	CLUB.alert.error("您所绑定的手机号码已经被该车友会封锁,请在个人中心更改绑定的手机号码！");
	        	return false;
	        }
	        return true;
		}
}
//首页发提问
CLUB.namespace("clubIndex.dyna.postQuestion");
CLUB.clubIndex.dyna.postQuestion={
    process:"&command=53003&command=53004&command=53016&command=53017&command=53018&command=53019&command=53020",
    uploadType:"image",
    flashId:"l_571x111_llx",
    flashUrl:"http://www1.pcauto.com.cn/flash/141226/cheyouhui/l_571x167_llx.swf?" + new Date().getTime(),
    flashWidth:571,
    flashHeight:111,
    getProcess:function() {
        return CLUB.clubIndex.dyna.postQuestion.process;
    },
    flashInitReady:false,
    flashInit : function(){
        var pc = CLUB.upload.initProcCommand("-quality 80");
        CLUB.upload.thisMovie(CLUB.clubIndex.dyna.postQuestion.flashId).sendToActionScript(pc);
        CLUB.clubIndex.dyna.postQuestion.flashInitReady=true;
    },
    getPictureNum:function() {
        if(CLUB.clubIndex.dyna.postQuestion.flashInitReady){
            return CLUB.upload.thisMovie(CLUB.clubIndex.dyna.postQuestion.flashId).getPictureNum();
        }else{
            return 0;
        }
    },
    imagesjson:"",
    isSend:false,
    forumId:0,
    alertErrorTip:function(txt){
        CLUB.alert.error(txt, false, "知道了");
    },
    loadWord:function(obj){
        var title = obj.value;
        $.ajax({
            url:"/bbs/intf/load/words.ajax",
            dataType:"json",
            data:{
                word : title
            },
            type:"get",
            success:function(data){
                $("#topicqType").val(data.cateId);
                $("#topicSubtype").val(data.subCateId);
            }
        });
    },
    commit:function(){//发表提问
        if(CLUB.clubIndex.dyna.postQuestion.isSend){
            CLUB.clubIndex.dyna.postQuestion.alertErrorTip("请不要重复提交!");
            return;
        }
        if(CLUB.global.mustBindPhone && !CLUB.global.isUserBindPhone){
        	CLUB.alert.error("您还没有绑定手机,该车友会只有绑定手机后才能互动,请到个人中心绑定手机号码");
        	return;
        }
        if(CLUB.global.isUserLock){
        	CLUB.alert.error("您所绑定的手机号码已经被该车友会封锁,请在个人中心更改绑定的手机号码！");
        	return;
        }
        var title =   $("#publish-box3 #subject").val();
        title = title=="请输入标题" ? "" :title;
        var len = title.length;
        var content = $("#publish-box3 textarea").val();
        content = content=="请输入具体的问题描述…" ? "" :content;
        var conLen = content.length;
        content = CLUB.emotion.transformToUBB(content)+CLUB.clubIndex.dyna.postQuestion.imagesjson;
        if(!title){
            CLUB.clubIndex.dyna.postQuestion.alertErrorTip("请先输入标题!");
            return;
        }
        if(!content){
            CLUB.clubIndex.dyna.postQuestion.alertErrorTip("请先输入内容");
            return;
        }
        if(len>35){
            CLUB.clubIndex.dyna.postQuestion.alertErrorTip("标题长度不能超过35字");
            return ;
        }
        if(conLen<10){
            CLUB.clubIndex.dyna.postQuestion.alertErrorTip("提问内容不能少于10字");
            return ;
        }
        if(conLen>1000){
            CLUB.clubIndex.dyna.postQuestion.alertErrorTip("提问内容不能超过1000字");
            return ;
        }
        CLUB.clubIndex.dyna.postQuestion.isSend = true;
        var cateId = $("#topicqType").val();
        var subCateId = $("#topicSubtype").val();
        $.ajax({
            url:"/bbs/action/topic/create.ajax",
            dataType:"json",
            data:{
                title : title,
                fid :CLUB.clubIndex.dyna.postQuestion.forumId,
                message:content,
                type :"question",
                qType:cateId,
                qSubtype:subCateId
            },
            type:"post",
            success:function(data){
                if(data.status==0){
                    CLUB.clubIndex.dyna.postQuestion.closeBox();
                    CLUB.alert.success("发表成功")
                    window.location.reload(true);
                }else{
                	CLUB.clubIndex.dyna.postQuestion.isSend = false;
                    CLUB.clubIndex.dyna.postQuestion.alertErrorTip(data.desc);
                }
            
            },
            error:function(xmlHttpRequest, textStatus, errorThrown){
                CLUB.clubIndex.dyna.postQuestion.isSend = false;
                CLUB.clubIndex.dyna.postQuestion.alertErrorTip("网络错误,请联系管理员");
            }
        });
    },
    upcAfter:function(imgData){
        var imagesjson = "";
        for(var i = 0; i < imgData.length; i++){
            if(imgData[i].url.indexOf("1024x1024")!=-1){
                imagesjson +="[img="+imgData[i].width+","+imgData[i].height+"]"+imgData[i].url+"[/img]";
            }
        }
        CLUB.clubIndex.dyna.postQuestion.imagesjson = imagesjson;
    },
    initFlash : function(divId) {
        var flashVars = "useExternalInterface=Yes&process=" + encodeURIComponent( CLUB.clubIndex.dyna.postQuestion.process) 
        +"&transactionUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/tx.jsp?application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT) 
        +"&uploadUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/upload_stream_flash.jsp?fileType=Picture&application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT)
        +"&flashWidth=" + encodeURIComponent( CLUB.clubIndex.dyna.postQuestion.flashWidth)
        +"&flashHeight=" + encodeURIComponent( CLUB.clubIndex.dyna.postQuestion.flashHeight)
        +"&keepSrc="+ encodeURIComponent(true)//保存原图
        +"&color="+ encodeURIComponent("0xFF6600")//框的颜色
        +"&fileSizeLimit="+ encodeURIComponent(10240)//限制文件大小
        +"&upcAfter="+ encodeURIComponent(" CLUB.clubIndex.dyna.postQuestion.upcAfter")
        +"&getCookie="+ encodeURIComponent("CLUB.upload.getCookie")
        +"&getFileTypes="+ encodeURIComponent("CLUB.upload.getFileTypes")
        +"&flashInit="+ encodeURIComponent(" CLUB.clubIndex.dyna.postQuestion.flashInit")
        +"&getProcess="+ encodeURIComponent(" CLUB.clubIndex.dyna.postQuestion.getProcess")
        +"&commit="+ encodeURIComponent(" CLUB.clubIndex.dyna.postQuestion.commit")
        +"&resizeFlash="+ encodeURIComponent("CLUB.upload.resizeFlash")
        +"&showHide="+ encodeURIComponent("CLUB.upload.showHide")
        +"&flashId="+ encodeURIComponent( CLUB.clubIndex.dyna.postQuestion.flashId)
        +"&tooltip="+ encodeURIComponent("CLUB.upload.tooltip")
        +"&uploadError="+ encodeURIComponent("CLUB.upload.uploadError")
        
        var flashContent = '<OBJECT id="'+ CLUB.clubIndex.dyna.postQuestion.flashId+'_ob" name="'+ CLUB.clubIndex.dyna.postQuestion.flashId+'_ob" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" WIDTH='+ CLUB.clubIndex.dyna.postQuestion.flashWidth+' HEIGHT='+ CLUB.clubIndex.dyna.postQuestion.flashHeight+'>'
        + '<PARAM NAME=movie VALUE="'+ CLUB.clubIndex.dyna.postQuestion.flashUrl+'">'
        + '<PARAM NAME=quality VALUE=high>'
        + '<PARAM NAME=wmode VALUE=transparent>'
        + '<PARAM NAME="allowScriptAccess" value="always">'
        + '<PARAM NAME="FlashVars" VALUE="' + flashVars + '">'
        + '<EMBED  id="'+ CLUB.clubIndex.dyna.postQuestion.flashId+'_em"  name="'+ CLUB.clubIndex.dyna.postQuestion.flashId+'_em" src="'+ CLUB.clubIndex.dyna.postQuestion.flashUrl+'" quality=high wmode="transparent" swLiveConnect=FALSE WIDTH='
        +  CLUB.clubIndex.dyna.postQuestion.flashWidth + ' HEIGHT='+ CLUB.clubIndex.dyna.postQuestion.flashHeight
        + ' flashvars="'+ flashVars + '" allowScriptAccess="always" ' 
        + ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>'
        + '</OBJECT>';
        $("#"+divId).html(flashContent);
        return flashContent;
    },
    init:function(){
        if(!CLUB.global.isMember || $("#publish #publish-th").length==0){
            return ;
        }
        //提问动画
        $("#publish .publish-btns-tw").click(function(){
            if(!CLUB.upload.isSupportFlash){
                CLUB.alert.error("该设备不支持发表动态",true,"知道了");
                return false;
            }
            if(CLUB.global.mustBindPhone && !CLUB.global.isUserBindPhone){
	        	CLUB.alert.error("您还没有绑定手机,该车友会只有绑定手机后才能互动,请到个人中心绑定手机号码");
	        	return false;
        	}
        if(CLUB.global.isUserLock){
        	CLUB.alert.error("您所绑定的手机号码已经被该车友会封锁,请在个人中心更改绑定的手机号码！");
        	return false;
        }
            CLUB.alert._maskBg.show();
            
            var fH=$("#publish").offset();
            var box=$("#publish-box3");
            box.css("left",fH.left+"px");
            box.css("top",fH.top+"px");
            box.slideDown();
            
            $('htmll,body').animate({
                scrollTop:fH.top-45
            });
            $("#publish").parent().css("visibility","hidden");
            $("#publish-th").hide();
            $("#publish-box3 .publish-box-face img").animate({
                width:70,
                height:70,
                marginTop:0,
                marginLeft:0,
                borderRadius:36
            }, 500);
        });
           $('.user-face').click(function(event){
            event.stopPropagation();
           })
           $("#publish-box3 .publish-cancel").click(function(){
            if(($("#publish-box3 textarea").val().length>0&&$("#publish-box3 textarea").val()!="请输入具体的问题描述…") 
                || ($("#subject").val().length>0 && $("#subject").val()!="请输入标题") ){
                CLUB.alert._show({
                    name:"alert",
                    tip:'未保存的内容将丢失,要继续吗？',
                    btnHtml:'<a class="cancel" href="javascript:void(0)" onclick="CLUB.alert.hide(false)">取消</a><a class="sure" href="javascript:void(0)" onclick="CLUB.clubIndex.dyna.postQuestion.closeBox()">确定</a>',
                    closeMask:false
                });
            }else{
                CLUB.clubIndex.dyna.postQuestion.closeBox();
            }
        });
        
        /*统计提问标题字数*/
        $("#publish-box3 input").keyup(function(){
            var l= CLUB.emotion.transformToUBB($(this).val()).length;
            $("#publish-box-input-num").html(l+'/35');
            if(l>35){
                $("#publish-box-input-num").css("color","red");
            }else{
                $("#publish-box-input-num").css("color","#777");
            }
        })
        
        /*提问上传图片*/
        CLUB.clubIndex.dyna.postQuestion.initFlash("blish-box-upload-flash2");
        
        $(".upload_flash_pic li") .live('mouseenter',function(){
            $(this).addClass("hover");
        }).live('mouseleave',function(){
            $(this).removeClass("hover");
        });
        CLUB.clubIndex.dyna.postQuestion.forumId=CLUB.global.forumId;
    }, 
    closeBox:function(){
        $("#publish-box3 .replyData-face").parent().find(".replyData-face-pop").hide();
        CLUB.alert.hide(false);
        CLUB.clubIndex.dyna.postQuestion.imagesjson ="";
        $("#topicqType").val(5);
        $("#topicSubtype").val(57);
        $("#publish-box-input-num").html('0/35');
        $("#publish-box3 textarea").val("请输入具体的问题描述…");
        $("#publish-box3 #subject").attr("style","color: #777");
        $("#publish-box3 #subject").val("请输入标题");
        $("#publish-box3 .publish-box-face img").animate({
            width:50,
            height:50,
            marginTop:14,
            marginLeft:20,
            borderRadius:25
        }, 500);
        $("#publish").parent().css("visibility","visible");
        $("#publish-box3").slideUp();   
        CLUB.alert._maskBg.hide();
        $("#publish-th").show();
        if(CLUB.upload.isSupportFlash){
            CLUB.clubIndex.dyna.postQuestion.initFlash("blish-box-upload-flash2");
        }
    }
}

// 首页回复
CLUB.namespace("clubIndex.reply");
CLUB.clubIndex.reply={
    getList:function(dynaInfoId,topicId,forumId,createBy,dynaType,activityId){
        CLUB.ajax.get(CLUB.global.ROOT+"/dyna/getReplyListByDynaInfoId.do?dynaInfoId="+dynaInfoId, {}, function(d){
            var data = d.data;
            data.topicId=topicId;
            data.forumId=forumId;
            data.dynaInfoId=dynaInfoId;
            data.createBy=createBy;
            data.clubUrl=CLUB.global.ROOT+"/brand/"+CLUB.global.clubUrl+"/";
            data.clubName=CLUB.global.clubName;
            data.BBSROOT=CLUB.global.BBSROOT;
            data.UCROOT=CLUB.global.UCROOT;
            data.oClubId=CLUB.global.oClubId;
            data.userId=CLUB.global.userId;
            data.dynaType = dynaType;
            data.activityId = activityId;
            data.showFunction="CLUB.emotion.showInReply(this);";
            data.selectFunction="CLUB.emotion.selectInReply(this);";
            for(var i=0,len=data.replyList.length;i<len;i++){
                data.replyList[i].content = CLUB.emotion.transformToHTML(data.replyList[i].content);
            }
            $("div[data-replyList="+dynaInfoId+"]").append(template("template-dynaReplyList", data));
            $("#reply-"+dynaInfoId).attr("isLoadingReply","false");
        }); 
    },
    showBtn:function(node){
        var $inner = $(node).parents("dd[data-reply-reply]").find(".replyData-inner");
        if($inner.length>0){
            $inner.remove();
        }else{
            var data={
                topicId:$(node).attr("data-topicId"),
                forumId:$(node).attr("data-forumId"),
                dynaInfoId:$(node).attr("data-dynaInfoId"),
                dynaReplyId:$(node).attr("data-dynaReplyId"),
                postToUserId:$(node).attr("data-postToUserId"),
                postToNickName:$(node).attr("data-postToNickName"),
                postId:$(node).attr("data-postId"),
                oClubId:$(node).attr("data-oClubId")
            };
            var html = template("template-dynaReplyReply",data);
            $(node).parents("dd[data-reply-reply]").append(html);
        }
    },
    updateReplyCount:function(dynaInfoId){
        var $replyCount = $("#reply-"+dynaInfoId+" s");
        var replyCount = parseInt($replyCount.text())+1;
        $replyCount.text(replyCount);
        $("#dynaInfoDiv-"+dynaInfoId+" .replyData-list span[name='replyCount']").text(replyCount);//这个元素不一定有
    }
};

// 终端页回复
CLUB.namespace("detail");
CLUB.detail={
    init:function(obj){
        CLUB.detail.praiseUserPageSize = obj.praiseUserPageSize;
        CLUB.detail.initPraise();
        CLUB.detail.initReply();
        CLUB.dyna.initFocus();
        CLUB.dyna.checkIsFocus();
        CLUB.stat.visitPage();
        CLUB.dyna.initImages();
    },
    dynaPraisePageNo:0,//动态点赞列表当前页码
    praiseUserPageSize:13,
    initPraise:function(){
        //自己点赞，点赞列表的头像有变化
        CLUB.dyna.initPraise(function(){
            if($("#praiseUserList a[data-userId]").length==CLUB.detail.praiseUserPageSize){
                $("#praiseUserList a[data-userId]:last").remove();
            }
            var data={};
            data.url = CLUB.global.UCROOT+"/"+CLUB.global.userId+"/";
            data.nickname=CLUB.global.nickName;
            data.avatar =CLUB.common.faceSizeUrl(CLUB.global.userId);
            data.userId =CLUB.global.userId;
            if($("#praiseUserList a[data-userId]").length==0){
                $("#praiseUserList").append(template('praiseUserSmallAvatar',data));
                $("#praiseUserList").show();
            }else{
                $("#praiseUserList a[data-userId]:first").before(template('praiseUserSmallAvatar',data));
            }                    
            $("#detail-replyData-tool").attr("style","top:65px");
        },function(){
            $("#praiseUserList a[data-userId="+CLUB.global.userId+"]").remove();
            if($("#praiseUserList a[data-userId]").length==0){
                $("#praiseUserList").hide();
                $("#detail-replyData-tool").attr("style","");
            }
        });
        //弹窗
        $("#more-zhan").click(function(){
            CLUB.alert._show({
                name:"zhan"
            });
            CLUB.detail.dynaPraisePageNo=0;//先次点都清0
            $("#listMorePraseUser").show();//这个要先显示
            CLUB.detail.listMorePraseUser($(this).attr("data-dynaInfoId"));
            $("#pop-zhan .pop-tb").niceScroll({  
                cursorcolor:"#bbb",  
                cursoropacitymax:1,  
                touchbehavior:false,  
                cursorwidth:"10px",  
                cursorborder:"0",  
                cursorborderradius:"5px"  
            });  
        });	
    },
    isInitingReply:false,
    initReply:function(){
        if(CLUB.detail.isInitingReply){
            return;
        }
        CLUB.detail.isInitingReply=true;
        $(".pinglun").live("click",function(){
            var dynaInfoId = $(this).attr("data-dynaInfoId");
            if($(this).attr("isShowReplyList")==="true"){
                $(this).attr("isShowReplyList","false");
                $("div[data-replyList="+dynaInfoId+"] .replyData").hide();
                return ;
            }
            $(this).attr("isShowReplyList","true");
            $("div[data-replyList="+dynaInfoId+"] .replyData").show(); 
            $(".replyData-inner").hide();
        });
        $("input[name=reply]").live("keyup",function(){
            var v = $(this).val();
            var $btn = $(this).parent(".replyData-inp").next().find(".reply-btn");
            if(v==""){
                $btn.attr("class","reply-btn reply-btn-disable");
            }else{
                $btn.attr("class","reply-btn");
            }
        });
    },
    //加载更多点赞的用户
    listMorePraseUser:function(dynaInfoId){
        CLUB.detail.dynaPraisePageNo++;
        if(CLUB.detail.dynaPraisePageNo==1){
            $("#praseList").html("");//第一页都清空，重新加载
        }
        $.get(CLUB.global.ROOT+"/dyna/getPraiseUserList.do?dynaInfoId="+dynaInfoId+"&pageNo="+CLUB.detail.dynaPraisePageNo, {}, function(d){
            if(d.code==0){
                var list = d.data.list;
                if(list.length<CLUB.detail.dynaPraisePageNo){
                    $("#listMorePraseUser").hide();
                }  
                for(var i=0,len=list.length;i<len;i++){
                    var data={};
                    data.url = CLUB.global.UCROOT+"/"+list[i].uid+"/";
                    data.nickname=list[i].nickname;
                    data.avatar =CLUB.common.faceSizeUrl(list[i].uid+"",50);
                    $("#praseList").append(template('praiseUserAvatar',data));
                } 
            }
        }, "json");
    }
}

CLUB.namespace("CLUB.admin.common");
CLUB.admin.common={
    changeMap:{
        isIntroduceChange:false,
        isNoticeChange:false
    },
    initCountWord:function(changeKey,elementId,maxLen){
        var maxstrlen = maxLen;   //输入框最大字数
        function checkWord(c) {
            var str = c.value,myLen = str.length;
            var wck = document.getElementById("wordCheck");   
            if (myLen > maxstrlen) {   
                c.value = str.substring(0, maxstrlen);
            }else {   
                wck.innerHTML = myLen;
            }
        }
        var otinp = document.getElementById(elementId);
        checkWord(otinp);
        otinp.onkeydown=function(){
            checkWord(this);
        }
        otinp.onkeyup=function(){
            checkWord(this);
        }
        otinp.onclick=function(){
            checkWord(this);
        }
        otinp.onchange=function(){
            CLUB.admin.common.changeMap[changeKey] = true;
        }
    },
    initLeaveNow:function(changeKey){
        //修改还没保存就离开当前页面的提示
        $("a").click(function(){
            var url = $(this).attr("href");
            if(url!=null && url.indexOf("http:")==0&&($(this).attr("target")!="_blank") && CLUB.admin.common.changeMap[changeKey] ){
                CLUB.alert.confirm('修改尚未保存，确定要离开吗?',"window.location.href='"+url+"'");
                return false;
            }
            return  true;
        });    
    }
}

// 基本信息设置
CLUB.namespace("admin.info");
CLUB.admin.info={
    save:function(){
        $("#submitBtn").attr("disabled",true).text("提交中……");
        CLUB.ajax.post($("#infoForm").attr("action"),$("#infoForm").serialize(),function(rs){
            CLUB.alert.success(rs.message);
            CLUB.admin.common.changeMap["isIntroduceChange"] = false;
            $("#submitBtn").attr("disabled",false).text("保存");
        },function(rs){
            CLUB.alert.error(rs.message);
            $("#submitBtn").attr("disabled",false).text("保存");
        });
    },
    init:function(){
        CLUB.admin.common.initCountWord("isIntroduceChange", "introduce", 40);
        CLUB.admin.common.initLeaveNow("isIntroduceChange");
    }
}

// 公告设置
CLUB.namespace("admin.notice");
CLUB.admin.notice={
    isSend:false,
    save:function(){
        if(CLUB.admin.notice.isSend){
            return;
        }
        CLUB.admin.notice.isSend = true;
        $("#submitBtn").attr("disabled",true).text("提交中……");
        CLUB.ajax.post($("#noticeForm").attr("action"),$("#noticeForm").serialize(),function(rs){
            CLUB.alert.success(rs.message);
            CLUB.admin.notice.isSend = false;
            CLUB.admin.common.changeMap["isNoticeChange"] = false;
            $("#submitBtn").attr("disabled",false).text("保存");
        },function(rs){
            CLUB.alert.error(rs.message);
            CLUB.admin.notice.isSend = false;
            $("#submitBtn").attr("disabled",false).text("保存");
        });
    },
    init:function(){
        CLUB.admin.common.initCountWord("isNoticeChange", "content", 50);
        CLUB.admin.common.initLeaveNow("isNoticeChange");
    }
}

CLUB.namespace("upload");
CLUB.upload={
    UPCROOT:"",
    ROOT:"",
    appName:"",
    sessionName:"",
    isSupportFlash:true,
    init:function(cfg){
        CLUB.upload.UPCROOT=cfg.UPCROOT;
        CLUB.upload.ROOT=cfg.ROOT;
        CLUB.upload.appName=cfg.appName;
        CLUB.upload.sessionName=cfg.sessionName;
    },
    getCookie:function() {
        var name = CLUB.upload.sessionName;
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) return unescape(arr[2]);
        return null;
    },
    upcAfter:function(){},
    resizeFlash:function(){},
    //2.上传前设置上传命令
    initProcCommand:function(cmds){
        var commands = new Array(cmds);
        var pc = new Array();
        for(var i = 0; i < commands.length;i++){
            var _cs = commands[i].split("-");
            var ms = new Object();
            for(var k = 0; k < _cs.length;k++){
                var c = CLUB.upload.trim(_cs[k]);
                if(c.length==0){
                    continue;
                }
                c = c.replace(/\s\+/g, "+" ).split(" ");
                var v = "";
                for(var j = 1; j < c.length;j++){
                    v += " "+((c[j] || "").replace( /'(\d+x\d+)([>\\^!<]{0,4})'/g, "$1,$2" ).replace( /[x\\+]/g, "," ).replace( /'/g, "" ));
                }
                ms[c[0]] = CLUB.upload.trim(v);
            }
            pc.push(ms);
        }		
        return pc; 
    },
    uploadError:function(msg){
        CLUB.alert.error(msg);
    },
    thisMovie:function(movieName) {
        if (navigator.appName.indexOf("Microsoft") != -1) {
            if(window[movieName+"_ob"]){
                return window[movieName+"_ob"];
            }else{
                return document[movieName+"_ob"];
            }
        } else {
            if(document[movieName+"_em"]){
                return document[movieName+"_em"];
            }else{
                return document[movieName];
            }
        }
    },
    trim:function(text) {
        return (text || "").replace( /^\s+|\s+$/g, "" );
    },
    getFileTypes:function(){
        return 'Images (*.jpg, *.jpeg, *.gif, *.png)\n *.jpg;*.jpeg;*.gif;*.png;';
    },
    tooltip : function(txt){
        CLUB.alert.error("不支持此格式");
    },
    showHide : function(){}
}
CLUB.namespace("upload.logo");
CLUB.upload.logo={
    process:"&command=53000&command=53029",
    uploadType:"image",
    flashId:"hb_459x452_llx",
    flashUrl:"http://www1.pcauto.com.cn/flash/141226/cheyouhui/hb_459x452_llx.swf?" + new Date().getTime(),
    flashWidth:459,
    flashHeight:452,
    getProcess:function() {
        return CLUB.upload.logo.process;
    },
    flashInit : function(){
        var pc = CLUB.upload.initProcCommand("-quality 80 -newName 'logo'");
        CLUB.upload.thisMovie(CLUB.upload.logo.flashId).sendToActionScript(pc);
    },
    saveDone:function(data){
        var img = data.files[0];
        for(var i = 0,len = data.files.length;i<len;i++){
            if(data.files[i].isorg==1){
                img = data.files[i];
            }
        }
        if(data.retCode==0){
            var imgName = img.fileName;
            var idx = imgName.indexOf('.');
            var newName = imgName.substring(0,idx)+"_150x150"+imgName.substring(idx)
            var src = img.url.replace(imgName, newName);
            $('#clubLogo').attr("src", src+'?time='+Math.random());
            $(".club-logo-r a img").attr("src",src+'?time='+Math.random());
            $('#clubLogoVal').val(img.url);
            CLUB.ajax.post($("#logoForm").attr("action"),$("#logoForm").serialize(),function(rs){
                CLUB.alert.success(rs.message)
            },function(rs){
                CLUB.alert.error(rs.message);
            });
        }
    },
    show : function(divId) {
        var flashVars = "useExternalInterface=Yes&process=" + encodeURIComponent(CLUB.upload.logo.process) 
        +"&upcTxUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/tx.jsp?application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT) 
        +"&upcUploadUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/upload_stream_flash.jsp?fileType=Picture&application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT)
        +"&flashWidth=" + encodeURIComponent(CLUB.upload.logo.flashWidth)
        +"&flashHeight=" + encodeURIComponent(CLUB.upload.logo.flashHeight)
        +"&keepSrc="+ encodeURIComponent(true)//保存原图
        +"&color="+ encodeURIComponent("0xFF6600")//框的颜色
        +"&boxWidth="+ encodeURIComponent(150)//中间截图框的宽
        +"&boxHeight="+ encodeURIComponent(150)//中间截图框的高
        +"&fileSizeLimit="+ encodeURIComponent(10240)//限制文件大小
        +"&upcAfter="+ encodeURIComponent("CLUB.upload.upcAfter")
        +"&getCookie="+ encodeURIComponent("CLUB.upload.getCookie")
        +"&getFileTypes="+ encodeURIComponent("CLUB.upload.getFileTypes")
        +"&flashInit="+ encodeURIComponent("CLUB.upload.logo.flashInit")
        +"&getProcess="+ encodeURIComponent("CLUB.upload.logo.getProcess")
        +"&saveDone="+ encodeURIComponent("CLUB.upload.logo.saveDone")
        +"&resizeFlash="+ encodeURIComponent("CLUB.upload.resizeFlash")
        +"&showHide="+ encodeURIComponent("CLUB.upload.showHide")
        +"&flashId="+ encodeURIComponent(CLUB.upload.logo.flashId)
        +"&tooltip="+ encodeURIComponent("CLUB.upload.tooltip")
        +"&uploadError="+ encodeURIComponent("CLUB.upload.uploadError")
        +"&titleTxt="+ encodeURIComponent("您可以拖动图片以裁剪满意的会标")//里面文字说明内容
        
        var flashContent = '<OBJECT id="'+CLUB.upload.logo.flashId+'_ob" name="'+CLUB.upload.logo.flashId+'_ob" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" WIDTH='+CLUB.upload.logo.flashWidth+' HEIGHT='+CLUB.upload.logo.flashHeight+'>'
        + '<PARAM NAME=movie VALUE="'+CLUB.upload.logo.flashUrl+'">'
        + '<PARAM NAME=quality VALUE=high>'
        + '<PARAM NAME=wmode VALUE=transparent>'
        + '<PARAM NAME="allowScriptAccess" value="always">'
        + '<PARAM NAME="FlashVars" VALUE="' + flashVars + '">'
        + '<EMBED  id="'+CLUB.upload.logo.flashId+'_em"  name="'+CLUB.upload.logo.flashId+'_em" src="'+CLUB.upload.logo.flashUrl+'" quality=high wmode="transparent" swLiveConnect=FALSE WIDTH='
        + CLUB.upload.logo.flashWidth + ' HEIGHT='+CLUB.upload.logo.flashHeight
        + ' flashvars="'+ flashVars + '" allowScriptAccess="always" ' 
        + ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>'
        + '</OBJECT>';
        $("#"+divId).html(flashContent);
        return flashContent;
    }
}
CLUB.namespace("upload.coverImage");
CLUB.upload.coverImage={
    process:"&command=53032&command=53033&command=53041",
    uploadType:"image",
    flashId:"zdy_280x140_llx",
    flashUrl:"http://www1.pcauto.com.cn/flash/141226/cheyouhui/zdy_280x140_llx.swf?" + new Date().getTime(),
    flashWidth:280,
    flashHeight:140,
    getProcess:function() {
        return CLUB.upload.coverImage.process;
    },
    flashInit : function(){
        var pc = CLUB.upload.initProcCommand("-quality 80 -newName 'coverImage'");
        CLUB.upload.thisMovie(CLUB.upload.coverImage.flashId).sendToActionScript(pc);
    },
    saveDone:function(data){
        var img = data.files[0];
        for(var i = 0,len = data.files.length;i<len;i++){
            if(data.files[i].isorg==1){
                img = data.files[i];
            }
        }
        if(data.retCode==0){
            var imgName = img.fileName;
            var idx = imgName.indexOf('.');
            var newName280 = imgName.substring(0,idx)+"_280x140"+imgName.substring(idx)
            var newName990 = imgName.substring(0,idx)+"_990x250"+imgName.substring(idx)
            var src280 = img.url.replace(imgName, newName280);
            var src990 = img.url.replace(imgName, newName990);
            $('#flash_file_div').attr("style", "background:url("+src280+") no-repeat 0 0");
            $('#clubCoverImageDiv').attr("style", "background:url("+src990+")");
            $('#coverImageVal').val(img.url);
            CLUB.ajax.post($("#coverImageForm").attr("action"),$("#coverImageForm").serialize(),function(rs){
                CLUB.alert.success(rs.message)
            },function(rs){
                CLUB.alert.error(rs.message);
            });
        }
    },
    show : function(divId) {
        var flashVars = "useExternalInterface=Yes&process=" + encodeURIComponent(CLUB.upload.coverImage.process) 
        +"&upcTxUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/tx.jsp?application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT) 
        +"&upcUploadUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/upload_stream_flash.jsp?fileType=Picture&application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT)
        +"&flashWidth=" + encodeURIComponent(CLUB.upload.coverImage.flashWidth)
        +"&flashHeight=" + encodeURIComponent(CLUB.upload.coverImage.flashHeight)
        +"&keepSrc="+ encodeURIComponent(true)//保存原图
        +"&color="+ encodeURIComponent("0xFF6600")//框的颜色
        +"&fileSizeLimit="+ encodeURIComponent(10240)//限制文件大小
        +"&upcAfter="+ encodeURIComponent("CLUB.upload.upcAfter")
        +"&getCookie="+ encodeURIComponent("CLUB.upload.getCookie")
        +"&getFileTypes="+ encodeURIComponent("CLUB.upload.getFileTypes")
        +"&flashInit="+ encodeURIComponent("CLUB.upload.coverImage.flashInit")
        +"&getProcess="+ encodeURIComponent("CLUB.upload.coverImage.getProcess")
        +"&saveDone="+ encodeURIComponent("CLUB.upload.coverImage.saveDone")
        +"&resizeFlash="+ encodeURIComponent("CLUB.upload.resizeFlash")
        +"&showHide="+ encodeURIComponent("CLUB.upload.showHide")
        +"&flashId="+ encodeURIComponent(CLUB.upload.coverImage.flashId)
        +"&tooltip="+ encodeURIComponent("CLUB.upload.tooltip")
        +"&uploadError="+ encodeURIComponent("CLUB.upload.uploadError")
        +"&titleTxt="+ encodeURIComponent("点击更换封面图")//里面文字说明内容
        var flashContent = '<OBJECT id="'+CLUB.upload.coverImage.flashId+'_ob" name="'+CLUB.upload.coverImage.flashId+'_ob" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" WIDTH='+CLUB.upload.coverImage.flashWidth+' HEIGHT='+CLUB.upload.coverImage.flashHeight+'>'
        + '<PARAM NAME=movie VALUE="'+CLUB.upload.coverImage.flashUrl+'">'
        + '<PARAM NAME=quality VALUE=high>'
        + '<PARAM NAME=wmode VALUE=transparent>'
        + '<PARAM NAME="allowScriptAccess" value="always">'
        + '<PARAM NAME="FlashVars" VALUE="' + flashVars + '">'
        + '<EMBED  id="'+CLUB.upload.coverImage.flashId+'_em"  name="'+CLUB.upload.coverImage.flashId+'_em" src="'+CLUB.upload.coverImage.flashUrl+'" quality=high wmode="transparent" swLiveConnect=FALSE WIDTH='
        + CLUB.upload.coverImage.flashWidth + ' HEIGHT='+CLUB.upload.coverImage.flashHeight
        + ' flashvars="'+ flashVars + '" allowScriptAccess="always" ' 
        + ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>'
        + '</OBJECT>';
        $("#"+divId).html(flashContent);
        return flashContent;
    }
}
CLUB.namespace("upload.focusImg");
CLUB.upload.focusImg={
    defaultImg:"",
    oClubId:0,
    process:"&command=53026&command=53027&command=53033",
    uploadType:"image",
    flashUrl:"http://www1.pcauto.com.cn/flash/141226/cheyouhui/zdy_459x452_llx.swf?" + new Date().getTime(),
    flashWidth:280,
    flashHeight:140,
    getProcess:function() {
        return CLUB.upload.focusImg.process;
    },
    flashInit1 : function(){
        var pc = CLUB.upload.initProcCommand("-quality 80 -newName 'focusImg'");
        CLUB.upload.thisMovie("swfload1").sendToActionScript(pc);
    },
    flashInit2 : function(){
        var pc = CLUB.upload.initProcCommand("-quality 80 -newName 'focusImg'");
        CLUB.upload.thisMovie("swfload2").sendToActionScript(pc);
    },
    flashInit3 : function(){
        var pc = CLUB.upload.initProcCommand("-quality 80 -newName 'focusImg'");
        CLUB.upload.thisMovie("swfload3").sendToActionScript(pc);
    },
    resizeFlash:function(status,id){
        //初始化
        if(status==1){
            $("#"+id).removeClass("swfloadload");
            $("#"+id+"K").removeClass("xian");
            $("#"+id+"B").removeClass("yin");
        }
        //编辑界面改变时
        if(status==2){
            $("#"+id).addClass("swfloadload");
            $("#"+id+"K").addClass("xian");
            $("#"+id+"B").addClass("yin");
        }
    },
    autoOrder:function(id){
        if(id==null) return;
        var focusImg1Seq = $("#focusImg1Seq").val();
        var focusImg2Seq = $("#focusImg2Seq").val();
        var focusImg3Seq = $("#focusImg3Seq").val();
        if(id==1){
            if(focusImg2Seq != 1 && focusImg3Seq!=1){
                $("#focusImg1Seq").val(1);
            }else if(focusImg2Seq != 2 && focusImg3Seq!=2){
                $("#focusImg1Seq").val(2);
            }else{
                $("#focusImg1Seq").val(3);
            }
        }else if(id==2){
            if(focusImg1Seq != 1 && focusImg3Seq!=1){
                $("#focusImg2Seq").val(1);
            }else if(focusImg1Seq != 2 && focusImg3Seq!=2){
                $("#focusImg2Seq").val(2);
            }else{
                $("#focusImg2Seq").val(3);
            }
        }else if(id==3){
            if(focusImg1Seq != 1 && focusImg2Seq!=1){
                $("#focusImg3Seq").val(1);
            }else if(focusImg1Seq != 2 && focusImg2Seq!=2){
                $("#focusImg3Seq").val(2);
            }else{
                $("#focusImg3Seq").val(3);
            }
        }
    },
    checkInfo:function(){
        var reg = /^[1-3]$/;
        var focusImg1Seq = $("#focusImg1Seq").val();
        var focusImg2Seq = $("#focusImg2Seq").val();
        var focusImg3Seq = $("#focusImg3Seq").val();
        var imgUrl1 = $("#imgUrl1").val();
        var imgUrl2 = $("#imgUrl2").val();
        var imgUrl3 = $("#imgUrl3").val();
        if(imgUrl1!="" && imgUrl1!=CLUB.upload.focusImg.defaultImg && !reg.test(focusImg1Seq)){
            CLUB.alert.error("请输入正确的焦点图1序号");
            return false;
        }
        if(imgUrl2 && imgUrl2!=CLUB.upload.focusImg.defaultImg && !reg.test(focusImg2Seq)){
            CLUB.alert.error("请输入正确的焦点图2序号");
            return false;
        }
        if(imgUrl3 && imgUrl3!=CLUB.upload.focusImg.defaultImg && !reg.test(focusImg3Seq)){
            CLUB.alert.error("请输入正确的焦点图3序号");
            return false;
        }
        return true;
    },
    saveDone:function(_obj,id,imgUrlId){
        var data  = _obj.files;
        for(var i =0;i<data.length;i++){
            if(data[i].url.indexOf("_280x140")!=-1){
                $("#"+id).attr("style","background:url("+data[i].url+") no-repeat 0 0");
            }
            if(data[i].isorg==1){
                $("#"+imgUrlId).val(data[i].url);
            }
        }
    },
    saveDone1:function(_obj){
        CLUB.admin.common.changeMap["isFocusImgChange"] = false;
        CLUB.upload.focusImg.saveDone(_obj,"jiaodian1","imgUrl1");
        CLUB.upload.focusImg.autoOrder(1);
    },
    saveDone2:function(_obj){
        CLUB.admin.common.changeMap["isFocusImgChange"] = false;
        CLUB.upload.focusImg.saveDone(_obj,"jiaodian2","imgUrl2");
        CLUB.upload.focusImg.autoOrder(2);
    },
    saveDone3:function(_obj){
        CLUB.admin.common.changeMap["isFocusImgChange"] = false;
        CLUB.upload.focusImg.saveDone(_obj,"jiaodian3","imgUrl3");
        CLUB.upload.focusImg.autoOrder(3);
    },
    show : function(divId,flashId,flashInit,saveDone) {
        var flashVars = "useExternalInterface=Yes&process=" + encodeURIComponent(CLUB.upload.focusImg.process) 
        +"&upcTxUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/tx.jsp?application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT) 
        +"&upcUploadUrl=" + encodeURIComponent(CLUB.upload.UPCROOT+"/upload_stream_flash.jsp?fileType=Picture&application="+CLUB.upload.appName+"&referer="+CLUB.upload.ROOT)
        +"&flashWidth=" + encodeURIComponent(CLUB.upload.focusImg.flashWidth)
        +"&flashHeight=" + encodeURIComponent(CLUB.upload.focusImg.flashHeight)
        +"&keepSrc="+ encodeURIComponent(true)//保存原图
        +"&color="+ encodeURIComponent("0xFF6600")//框的颜色
        +"&boxWidth="+ encodeURIComponent(260)//中间截图框的宽
        +"&boxHeight="+ encodeURIComponent(130)//中间截图框的高
        +"&imageScale="+ encodeURIComponent(2)//
        +"&fileSizeLimit="+ encodeURIComponent(10240)//限制文件大小
        +"&upcAfter="+ encodeURIComponent("CLUB.upload.upcAfter")
        +"&getCookie="+ encodeURIComponent("CLUB.upload.getCookie")
        +"&getFileTypes="+ encodeURIComponent("CLUB.upload.getFileTypes")
        +"&flashInit="+ encodeURIComponent(flashInit)
        +"&getProcess="+ encodeURIComponent("CLUB.upload.focusImg.getProcess")
        +"&saveDone="+ encodeURIComponent(saveDone)
        +"&resizeFlash="+ encodeURIComponent("CLUB.upload.focusImg.resizeFlash")
        +"&showHide="+ encodeURIComponent("CLUB.upload.showHide")
        +"&flashId="+ encodeURIComponent(flashId)
        +"&tooltip="+ encodeURIComponent("CLUB.upload.tooltip")
        +"&uploadError="+ encodeURIComponent("CLUB.upload.uploadError")
        +"&titleTxt="+ encodeURIComponent("更换焦点图")//里面文字说明内容
        
        var flashContent = '<OBJECT id="'+flashId+'_ob" name="'+flashId+'_ob" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" WIDTH='+CLUB.upload.focusImg.flashWidth+' HEIGHT='+CLUB.upload.focusImg.flashHeight+'>'
        + '<PARAM NAME=movie VALUE="'+CLUB.upload.focusImg.flashUrl+'">'
        + '<PARAM NAME=quality VALUE=high>'
        + '<PARAM NAME=wmode VALUE=transparent>'
        + '<PARAM NAME="allowScriptAccess" value="always">'
        + '<PARAM NAME="FlashVars" VALUE="' + flashVars + '">'
        + '<EMBED  id="'+flashId+'_em"  name="'+flashId+'_em" src="'+CLUB.upload.focusImg.flashUrl+'" quality=high wmode="transparent" swLiveConnect=FALSE WIDTH='
        + CLUB.upload.focusImg.flashWidth + ' HEIGHT='+CLUB.upload.focusImg.flashHeight
        + ' flashvars="'+ flashVars + '" allowScriptAccess="always" ' 
        + ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>'
        + '</OBJECT>';
        $("#"+divId).html(flashContent);
        return flashContent;
    },
    init:function(oClubId,defaultImg){
        CLUB.upload.focusImg.defaultImg = defaultImg;
        CLUB.upload.focusImg.oClubId = oClubId;
        CLUB.upload.focusImg.show("swfload1", "swfload1", "CLUB.upload.focusImg.flashInit1","CLUB.upload.focusImg.saveDone1");
        CLUB.upload.focusImg.show("swfload2", "swfload2", "CLUB.upload.focusImg.flashInit2","CLUB.upload.focusImg.saveDone2");
        CLUB.upload.focusImg.show("swfload3", "swfload3", "CLUB.upload.focusImg.flashInit3","CLUB.upload.focusImg.saveDone3");
        $(".box-b input").change(function(){
            CLUB.admin.common.changeMap["isFocusImgChange"] = true;
        });  
        CLUB.admin.common.initLeaveNow("isFocusImgChange");
        $('#Jsec .jiaodian').hover(function(){
            if($(this).find(".jiaodianA").attr("style").indexOf(CLUB.upload.focusImg.defaultImg)==-1){
                $(this).addClass('jiaodianHover');
            }
        },function(){
            $(this).removeClass('jiaodianHover');
        })
    },
    confirmDelImg:function(imgId,id){
        CLUB.alert.confirm('确定要删除该焦点图吗', 'CLUB.upload.focusImg.delImg('+imgId+','+id+')');
    },
    delImg:function(imgId,id){
        CLUB.ajax.post(CLUB.upload.ROOT+"/brand/club/deleteFocusImg.do", {
            oClubId: CLUB.upload.focusImg.oClubId, 
            imgId: imgId
        }, function(rs){
            CLUB.upload.focusImg.clear(id);
            CLUB.alert.hide(true);
        }, function(rs){
            CLUB.alert.error(rs.message)
        });
    },
    clear:function(id){
        $("#imgUrl"+id).val("");
        $("#title"+id).val("");
        $("#url"+id).val("");
        $("#focusImg"+id+"Seq").val("");
        $("#jiaodian"+id).attr("style","background:url('"+CLUB.upload.focusImg.defaultImg+"') no-repeat 0 0");
    },
    
    save:function(){
        if(!CLUB.upload.focusImg.checkInfo()){
            return;
        }
        $("#submitBtn").attr("disabled",true).text("提交中……");
        CLUB.ajax.post($("#focusImgForm")[0].action, $("#focusImgForm").serialize(), function(rs){
            CLUB.alert.success(rs.message);
            $("#submitBtn").attr("disabled",false).text("保存");
            CLUB.admin.common.changeMap["isFocusImgChange"] = false;
        },function(rs){
            CLUB.alert.error(rs.message);
            $("#submitBtn").attr("disabled",false).text("保存");
            CLUB.admin.common.changeMap["isFocusImgChange"] = false;
        });
    }
}